BestCoder Round #85
来源:互联网 发布:discover it 编辑:程序博客网 时间:2024/05/21 22:50
传送门:1001-sum (前缀和取模)
题意:有n个数,问存不存在连续子序列之和是m的倍数
思路:
如果前缀和存在%m后==0的不用考虑,YES
如果存在余数为1~m-1的个数大于一个时我们也能保证为YES 为什么呢? 我们假设pre[1~i]%m为k,pre[1~j]%m为k(j>i)
那么容易想到pre[i+1,j]%m==0
#include <bits/stdc++.h>#define Memset(x, a) memset(x, a, sizeof(x))using namespace std;const int N=1e5+10;int n,m,T;int pre[N],vis[N];inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();} return x*f;}int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); T=read(); while(T--){ int x; Memset(vis,0); n=read();m=read(); for(int i=1; i<=n ;i++){ x=read(); pre[i]=pre[i-1]+x; vis[pre[i]%m]++; } int flag=0; if(vis[0])flag=1; else{ for(int i=1; i<=m; i++){ if(vis[i]>=2){ flag=1;break; } } } if(flag)cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
传送门:1002-domino (贪心)
思路:肯定是距离越远,就越要用那k-1次去推,最后用1次把所有都推了就好了,所以是先sort一遍,倒着处理就好了。
#include<bits/stdc++.h>#define ll __int64using namespace std;int a[100010];int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); int T; cin>>T; while(T--){ int n,k; cin>>n>>k; for(int i=0; i<n-1; i++){ cin>>a[i]; } sort(a,a+n-1); ll ans=0; for(int i=n-2; i>=0; i--){ k--; if(k>=1)ans++; else ans+=a[i]+1; } ans++; cout<<ans<<endl; }}
传送门:1003-abs
思路:
由于y质因数分解式中每个质因数均出现2次,那么y是一个完全平方数,设y=z*z,题目可转换成求z,使得每个质因数出现1次. 我们可以暴力枚举z,检查z是否符合要求,显然当z是质数是符合要求,由素数定理可以得,z的枚举量在logn级别 复杂度 O(
4√nlog2√n)
#include <bits/stdc++.h>#define ll __int64using namespace std;const ll inf= 0x7fffffffffffffffLL;ll ans;ll n;bool check(ll x){ if(x<2)return false; ll t=x; for(ll i=2; i*i<=x; i++){ if(x%i==0){ if(x%(i*i)==0)return false; x/=i; } } ans=min(ans,abs(t*t-n)); return true;}inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();} return x*f;}int main(){ int T; scanf("%d",&T); while(T--){ n=read(); ll x=(ll)(sqrt(n)+0.5); ans=inf; int flag=0; for(int i=0; ; i++){ if(check(x+i))flag=1; if(check(x-i))flag=1; if(flag)break; } printf("%I64d\n",ans); } return 0;}
1 0
- BestCoder Round #85
- BestCoder Round #85
- BestCoder Round #85题解
- BestCoder Round #85
- BestCoder Round #85
- BestCoder Round #85
- BestCoder Round #85
- BestCoder Round #85 前三题
- BestCoder Round #85题解
- BestCoder Round #85题解报告
- BestCoder Round #85 1001 1002
- BestCoder Round #85 题解(待续)
- BestCoder Round #85-1003 abs
- BestCoder Round #85 前三题题解
- Bestcoder round#85 解题报告
- BestCoder Round #85 1001 sum
- BestCoder Round #85题解报告
- BestCoder Round #85-1005 gcd
- JSTL
- Eclipse Class Decompiler——Java反编译插件
- win10 uwp 读取文本GBK错误
- 快速排序算法(Java)
- 随想录(推荐《自制编译器》这本书)
- BestCoder Round #85
- Mybatis的配置以及实例测试
- c语言:数据的输入
- thinkpad机械硬盘换SSD固态硬盘的总结
- java面试题5--String 的==和equals()方法
- Linux下创建和使用静态库、共享库的方法总结
- 【机房合作——类图生成框架】
- Hdu 2067 小兔的棋盘 (卡特兰数)
- VS加载项目时报错 尚未配置为Web项目XXXX指定的本地IIS