冬令时之后,这cf的时间也是醉了 - 。-||,而且这场还是unrated...
一个工厂第一天开始有n个物品,每天结束生产n%m件物品,则第二天开始时有n+n%m件物品,问会不会在某天结束之后物品数%m==0
#include <cstdio> //如果存在k使n*2^k%m==0,则生产停止 #include <cstring> //k的最大值为O(log(2)m) //枚举到20天就行,如果不停止 typedef long long LL; //以后也不会停止 int main() { LL n, m; scanf("%lld%lld", &n, &m); bool ok = true; LL s = n; LL fir = n%m; for (int i = 0; i < 20; i++) { s += s%m; if (s%m==0) {ok = false; break;} } printf(ok? "No\n" : "Yes\n"); return 0; }
给出二维平面上一些点,求包含这些点的最小正方形的面积
#include <cstdio> #include <cstring> #include <algorithm> #include <string> using namespace std; typedef long long LL; #define INF (int)1e9; int main() { int n; LL maxx = -INF; LL maxy = -INF; LL minx = INF; LL miny = INF; scanf("%d", &n); for (int i = 0; i < n; i++) { LL x, y; scanf("%lld%lld",&x, &y); maxx = max(maxx,x); minx = min(minx,x); maxy = max(maxy,y); miny = min(miny,y); } LL s = max((maxx-minx),(maxy-miny))*max((maxx-minx),(maxy-miny)); printf("%lld\n",s); return 0; }
求从l到r中最小的数k,把k转换成二进制后k中含有的1的个数不小于[l,r]中的其他数中1的个数
#include <cstdio> #include <cstring> #include <algorithm> #include <string> using namespace std; typedef long long LL; int main() { int tcase; scanf("%d", &tcase); while (tcase--) { LL ll, rr; scanf("%lld%lld", &ll, &rr); // 感觉这种方法比题解给的好 LL tep = 1; //为了使这个数尽量小,我们尽可能的从低位开始补1 for (LL i = 0; i < 64; i++) { LL t = tep|ll; if (t > rr) break; ll = t; tep <<= 1; } printf("%lld\n", ll); } return 0; }
给出数列A0,A1,A2....An,求在Ai>Aj条件下最大的 Ai%Aj
#include <cstdio> #include <algorithm> int A[2100000]; int main() { int n, tep; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &tep); A[tep] = tep; } for (int i = 1; i <= 2000000; i++) if (A[i] == 0) A[i] = A[i-1]; int maxx = 0; for (int i = 1; i <= 2000000; i++) if (A[i] == i) for (int j = i-1; j <= 2000000; j+= i) if (i <= A[j] && maxx < A[j]%i) maxx = A[j]%i; printf("%d\n", maxx); return 0; }