当前位置:网站首页>牛客白月赛5 【题解 数学场】
牛客白月赛5 【题解 数学场】
2022-04-22 06:58:00 【辉小歌】
数学场
https://ac.nowcoder.com/acm/contest/135#question
目录
无关(relationship)【容斥】

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N=25;
LL l,r,n,a[N];
LL solve(LL x)
{
LL sum=0;
for(int i=1;i<(1<<n);i++)
{
LL temp=x,cnt=-1;
for(int j=0;j<n;j++)
{
if((i>>j)&1==1) temp/=a[j],cnt=cnt*(-1);
}
sum=sum+cnt*temp;
}
return x-sum;
}
int main(void)
{
cin>>l>>r>>n;
for(int i=0;i<n;i++) cin>>a[i];
cout<<solve(r)-solve(l-1);
return 0;
}
范围(range)【不会】
水题(water)【不会】
阶乘(factorial)【思维 末尾0的个数】

2*5==10 2的个数一定大于5的个数。故就是求5的个数。
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
LL sum,n,cnt;
int main(void)
{
cin>>n;
for(int i=1;i<=n;i++)
{
int j=i;
while(j%5==0) cnt++,j/=5;
sum+=cnt;
}
cout<<sum;
return 0;
}
面积(area)【不会】
圆(circle)【n个点将圆分成几部分】


#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
int main(void)
{
LL n;
while(cin>>n)
{
LL sum=0;
if(n>=4) sum+=n*(n-1)*(n-2)*(n-3)/4/3/2;
if(n>=2) sum+=n*(n-1)/2;
sum++;
cout<<sum<<endl;
}
return 0;
}
异或(xor)

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
LL n;
int main(void)
{
while(scanf("%lld",&n)!=-1) printf("%lld\n",n/3*2+n%3);
return 0;
}
最大公约数(lcm)

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
LL gcd(LL a,LL b){
return b?gcd(b,a%b):a;}
int main(void)
{
LL a,b; cin>>a>>b;
cout<<a/gcd(a,b)*b;
return 0;
}
区间 (interval)【差分】

#include<bits/stdc++.h>
using namespace std;
const int N=1e6*3+10;
typedef long long int LL;
LL n,m,x,a[N];
void add(int l,int r,int x)
{
a[l]+=x;
a[r+1]-=x;
}
int main(void)
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>x,add(i,i,x);
while(m--)
{
LL op,l,r,p; cin>>op>>l>>r>>p;
if(op!=1) add(l,r,p);
else add(l,r,-p);
}
for(int i=1;i<=n;i++) a[i]+=a[i-1];
LL sum=0,l,r;
cin>>l>>r;
for(int i=l;i<=r;i++) sum+=a[i];
cout<<sum<<endl;
return 0;
}
时间(time)【模拟】

#include<bits/stdc++.h>
using namespace std;
bool check(int x,int y)
{
int a1=x/10,a2=x%10;
int b2=y/10,b1=y%10;
if(a1==b1&&a2==b2) return true;
return false;
}
int main(void)
{
string s; cin>>s;
int a,b;
a=stoi(s.substr(0,s.find(':')));
b=stoi(s.substr(s.find(':')+1));
int x=0,y=0;
for(int i=0,j=0;;j++)
{
if(j==60) j=0,i++;
if(i==a&&j==b) break;
if(check(i,j)) x=i,y=j;
}
printf("%d:%d\n",x,y);
x=0,y=0;
for(int i=a,j=b+1;;j++)
{
if(j==60) j=0,i++;
if(i==24) break;
if(check(i,j))
{
x=i,y=j;
break;
}
}
printf("%d:%d\n",x,y);
return 0;
}
版权声明
本文为[辉小歌]所创,转载请带上原文链接,感谢
https://huixiaoge.blog.csdn.net/article/details/124329917
边栏推荐
猜你喜欢

Web automation: how to realize browser window scrolling in 8.3 selenium

adb logcat 日志

laravel 自带分页查询

氧化镁MgO晶体基片|钛酸锶SrTiO3晶体基片|铌酸锂LiNbO3晶体基片;直径10mm

荧光标记的多肽/氨基酸(FITC修饰/AMC修饰)齐岳生物

无水葡萄糖 cas:50-99-7 D(+)-Glucose 分子量:180.156 分子式:C6H12O6 密度及沸点值

软件测试面试题汇总

MYSQL03_SQL的概述、规则和规范、基本的SELECT语句、显示表结构

荧光标记的透明质酸|FITC-Hyaluronate|荧光素透明质酸|Fluorescent hyaluronic acid

Cherno_游戏引擎系列教程(5):101~
随机推荐
汉源高科8E1专网4路百兆隔离网络PDH光端机E1专网业务16M业务光端机
monkey 实战
OpenFeign组件的简介和使用
CAS:36530-06-0氯化硼亚酞菁|亚酞菁|氯化硼亚酞菁|二氯硼酞菁染料|氯化亚酞菁硼|BORONSUBPHTHALOCYANINECHLORIDE
Flink 指标参数源码解读(读取数量、发送数量、发送字节数、接收字节数等)
systemctl启动prometheus+grafana环境
laravel 自带分页查询
PDH光端机综合多业务光接入设备双光口传16路E1 2M+4路千兆1000M网络+4路百兆共享网络机架式双电源
unittest框架
MYSQL_从精通到放弃目录
Unittest framework
分布式系统服务熔断
tf.keras.layers.Embedding函数
Leprechaun green elf magic strikes
Integrated optical access equipment 4-way 100m isolated Ethernet + 16-way E1 private network service 2m integrated service optical transceiver
Byte experts jointly create the latest jetpack compose complete set of learning notes, including project practice exercises (with demo)
OpenFeign的细节展示
综合业务PDH光端机4路千兆隔离以太网络+4路E1专网业务2M综合业务光端机
ADB logcat log
宝塔面板设置django纯接口和channel及mysql遇到的一些问题记录