【Codeforces】Rand#417解题报告

  • 本文为博主原创,未经许可不得转载

Sagheer and Crossroads

if大判断即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<bits/stdc++.h>
#define FILE "read"
using namespace std;
int flag[10],a[10][10];
int main(){
//freopen(FILE".in","r",stdin);
//freopen(FILE".out","w",stdout);
for(int i=1;i<=4;++i)for(int j=1;j<=4;++j)cin>>a[i][j];
if(a[1][1]||a[1][2]||a[1][3]||a[2][1]||a[3][2]||a[4][3]) flag[1]=1;
if(a[2][1]||a[2][2]||a[2][3]||a[3][1]||a[4][2]||a[1][3]) flag[2]=1;
if(a[3][1]||a[3][2]||a[3][3]||a[4][1]||a[1][2]||a[2][3]) flag[3]=1;
if(a[4][1]||a[4][2]||a[4][3]||a[1][1]||a[2][2]||a[3][3]) flag[4]=1;
for(int i=1;i<=4;++i) if(a[i][4]&&flag[i]) flag[0]=1;
if(flag[0]) puts("YES");
else puts("NO");
return 0;
}

  

  

Sagheer the Hausmeister

暴力搜索上楼顺序,赛场上写的dp居然挂了,死活过不去5555

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<bits/stdc++.h>
#define FILE "read"
#define INF 1e9
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
using namespace std;
int n,m,maxx,ans,L[25],R[25];
char ch[25][105];
inline int read(){
int x=0,f=1; char ch=getchar();
while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int solve(int S){
int now=0,ret=0;
for(int i=1;i<=maxx;++i){
if(now==0) now=R[i],ret+=R[i];
else now=L[i],ret+=m+1-L[i];
if(i==maxx) break;
if((1<<i)&S) ret+=m+1-now,now=m+1;
else ret+=now,now=0;
ret++;
}
return ret;
}
int main(){
//freopen(FILE".in","r",stdin);
//freopen(FILE".out","w",stdout);
n=read(); m=read(); ans=INF;
for(int i=n;i;--i) scanf("%s",ch[i]);
for(int i=1;i<=n;++i)L[i]=m+1;
for(int i=1;i<=n;++i)for(int j=0;j<=m+1;++j)if(ch[i][j]=='1'){
cmin(L[i],j);
cmax(R[i],j);
maxx=i;
}
for(int i=0;i<(1<<(maxx+1));++i)cmin(ans,solve(i));
printf("%d\n",ans);
return 0;
}

  

  

Sagheer and Nubian Market

本场比赛最水的题目,二分即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<bits/stdc++.h>
#define FILE "read"
#define MAXN 100100
using namespace std;
typedef long long ll;
ll n,S,a[MAXN],b[MAXN];
inline ll read(){
ll x=0,f=1; char ch=getchar();
while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
ll get(ll mid){
for(ll i=1;i<=n;++i) b[i]=a[i]+mid*i;
sort(b+1,b+n+1);
ll ret=0;
for(ll i=1;i<=mid;++i) ret+=b[i];
return ret;
}
bool check(ll mid){
ll ret=get(mid);
return ret<=S;
}
int main(){
//freopen(FILE".in","r",stdin);
//freopen(FILE".out","w",stdout);
n=read(); S=read();
for(ll i=1;i<=n;++i) a[i]=read();
ll l=0,r=n;
while(l+1<r){
ll mid=(l+r)>>1;
if(check(mid)) l=mid;
else r=mid;
}
if(check(r)) printf("%lld %lld\n",r,get(r));
else printf("%lld %lld\n",l,get(l));
return 0;
}

  

  

Sagheer and Apple Tree

阶梯博弈,后手必胜的条件是所有偶数层的异或和为0

随便维护一下就好了

注意特判当前状态已经合法的情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<bits/stdc++.h>
#define FILE "read"
#define MAXN 100100
using namespace std;
typedef long long ll;
inline ll read(){
ll x=0,f=1; char ch=getchar();
while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
ll n,cnt,vout,ans,a[MAXN],f[MAXN],P[MAXN],st[MAXN],degree[MAXN],vis[10000100];
queue<ll>q;
int main(){
//freopen(FILE".in","r",stdin);
//freopen(FILE".out","w",stdout);
n=read(); memset(P,-1,sizeof(P));
for(ll i=1;i<=n;++i) a[i]=read();
for(ll i=2;i<=n;++i) f[i]=read(),degree[f[i]]++;
for(ll i=1;i<=n;++i)if(degree[i]==0)q.push(i),P[i]=0;
while(!q.empty()){
ll x=q.front(); q.pop();
if(--degree[f[x]]==0) q.push(f[x]);
P[f[x]]=P[x]^1;
}
for(ll i=1;i<=n;++i){
if(P[i]==0) st[++cnt]=a[i],ans^=a[i];
else vis[a[i]]++;
}
for(ll i=1;i<=cnt;++i){
ll temp=ans^st[i];
if(temp>10000000) continue;
vout+=vis[temp];
}
if(ans==0) vout+=(cnt-1)*cnt/2+(n-cnt)*(n-cnt-1)/2;
printf("%lld\n",vout);
return 0;
}
文章目录
  1. 1. Sagheer and Crossroads
  2. 2. Sagheer the Hausmeister
  3. 3. Sagheer and Nubian Market
  4. 4. Sagheer and Apple Tree
,