A - 栗酱的亦或和
nim游戏
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int T,x,y,z,n,m;
int a[N];
int main()
{
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
int sum = 0;
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
if(i==m-1) continue;
if(i) sum ^= a[i];
else sum = a[i];
}
if(sum==0) printf("Yes\n");
else{
if(sum<a[m-1]) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
D - 简单的数据结构
模拟
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N = 1e6 + 10;
bool cmp(int a,int b){
return a>b;
}
int n,m,a,ope,st[N],be=50000+10,ed=50000+9,re=0,num=0;
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
scanf("%d",&ope);
if(ope==1||ope==3){
scanf("%d",&a);
num++;
if(ope==1){
if(re) st[++ed] = a;
else st[--be] = a;
}else{
if(!re) st[++ed] = a;
else st[--be] = a;
}
}else{
if(!re){
switch(ope){
case 2:be++; num--; break;
case 4:ed--; num--; break;
case 5:re = !re; break;
case 6:
printf("%d\n",num);
for(int i=be;i<=ed;i++)
printf("%d%c",st[i],i==ed?'\n':' ');
break;
case 7:sort(st+be,st+ed+1); break;
}
}else{
switch(ope){
case 4:be++; num--; break;
case 2:ed--; num--; break;
case 5:re = !re; break;
case 6:
printf("%d\n",num);
for(int i=ed;i>=be;i--)
printf("%d%c",st[i],i==be?'\n':' ');
break;
case 7:sort(st+be,st+ed+1,cmp); break;
}
}
}
}
return 0;
}
I - 栗酱数数
暴力
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++){
if(!(i%4)) continue;
int now = i, flag = 0;
while(now){
if(now%10==4) {
flag = 1;
break;
}
now /= 10;
}
if(flag) continue;
printf("%d\n",i);
}
return 0;
}
J - 裁缝大师
极坐标#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int N = 1e5 + 10;
const double PI = 4 * atan(1.0);
int T;
double x,y,z,n,m;
int a[N];
int main()
{
scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf%lf",&x,&y,&z,&n);
double ang1 = 2 * PI / n;
double p = 0;
double x0,y0;
x0 = x+z; y0 = y;
printf("%.2lf %.2lf\n",x0,y0);
for(int i=1;i<n;i++){
p -= ang1;
x0 = z*cos(p)+x; y0 = z*sin(p)+y;
if(fabs(x0)<0.01) x0 = 0;
if(fabs(y0)<0.01) y0 = 0;
printf("%.2lf %.2lf\n",x0,y0);
}
}
return 0;
}
K - 栗酱的连通图
贪心
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N = 1e3 + 10;
int T,x,y,z,n,m;
int a[N];
int main()
{
scanf("%d",&T);
while(T--){
int sum = 0, mx = 0;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
sum += a[i]/2;
mx = max(mx, a[i]/2);
}
sum += (n-2) * mx;
printf("%d\n",sum);
}
return 0;
}
L - 取数游戏
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N = 1e2 + 10;
int T,x,y,z,n,m;
int a[N];
int main()
{
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&a[0],&a[1],&a[2]);
sort(a,a+3);
printf("%d%d%d\n",a[2],a[1],a[0]);
}
return 0;
}
贪心
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N = 1e3 + 10;
int T,x,y,z,n,m;
int a[N];
int main()
{
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
scanf("%d",&m);
sort(a,a+n);
x = y = z = -1;
for(int i=0;i<n;i++){
if(x<=a[i]) x = a[i] + m;
else if(y<=a[i]) y = a[i] + m;
else if(z<=a[i]) z = a[i] + m;
else {
if(x<=y&&x<=z) x += m;
else if(y<=x&&y<=z) y += m;
else z += m;
}
}
printf("%d\n",max(x,max(y,z)));
}
return 0;
}