真是状况百出的一次CF啊……
最终还Unrated了,你让半夜打cf 的我们如何释怀(中途茫茫多的人都退场了)……虽说打得也不好……
在这里写一下这一场codeforces的解题报告,A-E的 题目及AC代码,部分题目有简单评析,代码还算清晰,主要阅读代码应该不难以理解。
那就用大小为m的一个vis数组来记录当前余数是否被用过,然后模拟,每次记录当前余数,如果余数变成0了输出Yes,如果余数到达了曾经有过的余数位置,那么就会以此为一个循环永远循环下去,那么我们break,输出No
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
int main()
{
int a,m; cin>>a>>m;
int vis[100086]={0};
while(1)
{
if(a==0){cout<<"Yes";return 0;}
if(vis[a]==1){cout<<"No";return 0;}
vis[a]=1;
a=(a+a)%m;
}
return 0;
}
这不知道算不算凸包,反正记录最大最小的x和y,然后相减获得最小矩形长宽,取两者较长边平方即可。
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf=(int)1e9+10086;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
bool cmp(const int a, const int b)
{
return a > b;
}
int main()
{
int n; cin>>n;
int up=-inf,down=inf,left=inf,right=-inf;
for(int i=0;i<n;i++)
{
int x,y; cin>>x>>y;
if(x<left) left=x;
if(x>right) right=x;
if(y<down) down=y;
if(y>up) up=y;
}
int len=max(up-down,right-left);
cout<<(long long)len*len;
return 0;
}
这题是给一个范围(L是左边界,R是有边界)问你在这个范围内哪个数载二进制下1的数量是最多的(有多个解请输出最小数)。
也就是,要二进制的1尽量多,还要求尽量小,那就从低位开始把0变成1呗
那么我们就从左边界开始,从低位向高位按位或(0变成1,1也还是1)1,直到比R大停止,输出前一个(即比R小的最后一个数)。
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
int main()
{
int cases=0;
scanf("%d",&cases);
for(int _case=1;_case<=cases;_case++)
{
ll l,r,t,p=1; cin>>l>>r;
for(ll i=0;i<63;i++)
{
ll t=l|p;
if(t>r)break;
l=t,p<<=1;
//cout<<t<<endl;
}
cout<<l<<endl;
}
return 0;
}
int n=0; cin>>n;
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
sort(num,num+n,cmp);
int modmax=0;
for(int i=0; num[i]>modmax; i++)
for(int j=i+1;num[j]>modmax && j<n; j++)
update( num[i] % num[j]);
cout<<modmax;
return 0;
这样的东西……TLE的飞起……
想了想就不能暴力啊,暴力的话剪枝也没用
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,a[200048]={0},ans=0;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define update(x) ans=(ans<(x)?x:ans);
int main()
{
scanf("%d",&n);
for(int i=0;i<n;++i) scanf("%d",&a[i]);
sort(a,a+n);
for(int i=0;i<n-1;++i)
if(i==0||a[i]!=a[i-1])
{
int j=a[i]+a[i],p;
while(j <= a[n-1])
{
p = lower_bound(a,a+n,j)-a;
if(p > 0) update(a[p-1] % a[i]);
j+=a[i];
}
update(a[n-1] % a[i]);
}
printf("%d\n",ans);
return 0;
}
DIV2全场只有一个人(joker99)出了E,看了下代码暂时囫囵吞了下,贴一下代码等日后学习下。
Code:
#include <cmath>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
const int size = 2 * 1000 * 1000 + 10;
const int ssize = 21;
char buf[size];
char nbuf[size];
int n=0, m=0;
int pwr[ssize][size];
void combine(int* tg, int* a, int* b, int shift)
{
for (int i = 0; i < n; i++)
{
if (a[i] < shift) tg[i] = a[i];
else tg[i] = b[a[i] - shift] + shift;
}
}
int main()
{
scanf("%s", buf); n = strlen(buf);
scanf("%d", &m);
for (int i = 0; i < m; i++)
{
int k, d;
scanf("%d%d", &k, &d);
int num = n - k + 1, cur = 0;
for (int j = 0; j < d; j++)
{
int p = j;
while (p < k)
{
pwr[0][p] = cur++;
p += d;
}
}
for (int j = k; j < n; j++) pwr[0][j] = j;
int lim = 0, vl = 1;
while (vl <= num)
{
vl *= 2;
lim++;
}
for (int j = 1; j < lim; j++)
combine(pwr[j], pwr[j - 1], pwr[j - 1], (1 << (j - 1)));
for (int j = 0; j < n; j++)
{
int ps = j;
int vl = num;
int sh = 0;
for (int h = lim - 1; h >= 0; h--)
if (vl >= (1 << h))
{
if (ps >= sh) ps = pwr[h][ps - sh] + sh;
vl -= (1 << h);
sh += (1 << h);
}
nbuf[ps] = buf[j];
}
for (int j = 0; j < n; j++) buf[j] = nbuf[j];
printf("%s\n", buf);
}
return 0;
}