cf276 div2
来源:互联网 发布:淘宝确认收货时间多久 编辑:程序博客网 时间:2024/06/09 22:10
A:给了两个数a和m,当天需要再生产a%m个产品,如果哪一天的产品总数是m的倍数了,就NO。否则yes。
每天生产的产品个数肯定是[0, m-1]所以如果在m+1天都没有出现是m的倍数了,以后也不可能。
int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); LL a, m, f = 0; cin >> a >> m; for(int i = 1; i <= m + 1; i++) { if(a % m == 0) {f = 1; break;} a = a + a % m; } if(f) cout << "Yes" << endl; else cout << "No" << endl; return 0;}
B:找到一个最大的正方形包含所有点
int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n; LL xl, xr, yb, yt, x, y; cin >> n >> x >> y; xl = xr = x; yb = yt = y; while(--n) { cin >> x >> y; xl = min(xl, x); xr = max(xr, x); yb = min(yb, y); yt = max(yt, y); } LL s = max(xr - xl, yt - yb); cout << s * s << endl; return 0;}
C:给定一个区间[L, R] 找到一个数使得二进制表示中1的个数最多,且这个数越小越好。
贪心,每次把最低位不是1的变为1即可。
LL l, r, ans;void solve(){ LL p = 1, ans = l; for(int i = 1; i < 64; i++) { l = ans | p; if(l > r) break; if(l > ans) ans = l; p <<= 1; } cout << ans << endl;}int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n; cin >> n; while(n--) { cin >> l >> r; solve(); } return 0;}
D:http://codeforces.com/contest/485/problem/D
我们先用a数组记录下<=a的最大的数是多少
那么对于数x,使得y % x最大的y一定是 y = {a[2*x-1], a[3*x-1], ......}最大的一个。
typedef long long LL;#define M 1000010int a[M];int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n, x, i, j, m = -1, ans = 0; cin >> n; rep(i, 1, n) {cin >> x; m = max(m, x); a[x] = x;} rep(i, 1, m) if(a[i] != i) a[i] = a[i-1]; rep(i, 1, m) { if(a[i] != i) continue; for(j = i + i - 1; j <= m; j += i) ans = max(ans, a[j] % i); ans = max(ans, a[m] % i); } cout << ans << endl; return 0;}
0 0
- cf276 div2
- SRM151 DIV2
- srm554 div2
- srm555 div2
- div2-20121206
- div2-20121208
- div2-20121209
- SRM565 DIV2
- Codeforce172 Div2
- Codeforce173 Div2
- cf174#div2
- 185div2
- 183div2
- 191 DIV2
- codeforces192 div2
- SRM587 (div2)
- SRM588 div2
- SRM602 (div2)
- 1000内素数 1000内回文数
- 使用 VS 2012 编译 GTest 遇到的编译错误
- Div里面载入另一个页面的实现(取代框架)(AJax)
- ORACLE_数据处理
- Android实战技术: 用Dimension解决多屏幕适配的问题
- cf276 div2
- MTT和S-MTT 跟踪器阅读总结
- SpringMVC的工作原理的解释和它的流程图
- FLV文件格式分析
- ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
- 第11周上机实践项目4——特殊三位数
- [Android]-图片JNI(C++\Java)高斯模糊的实现与比较
- ARMv8 中断机制
- Android Dialog修改小结