太久没有写博客了水一篇,仅记录一下暑期裸考参加的两场 2022 RoboCom ,半年来都在忙着读联考和考研,题解没有时间写了 QAQ,期待回归。
省赛
RC-u1
#include <bits/stdc++.h>
using namespace std;
ll n,m,c=0,ans=0;
ll main() {
cin>>n>>m;
for (ll i=1;i<=n;i++) {
ll p; cin>>p;
if (c+p>m) ans++,c=min(p,m);
else c+=p;
//printf("now = %d\n",c);
}
cout<<ans;
return 0;
}
RC-u2
#include <bits/stdc++.h>
#define MAXN 1007
#define INF 0x3f3f3f3f
using namespace std;
ll n,m,gap[MAXN],last[MAXN];
ll main() {
for (ll i=0;i<1007;i++) last[i]=-INF;
cin>>n>>m;
for (ll i=1;i<=n;i++) {
cin>>gap[i];
}
for (ll i=1;i<=m;i++) {
ll t,k; cin>>t>>k;
for (ll j=1;j<=k;j++) {
ll p; cin>>p;
if (t-last[p]<gap[p])
printf("Don't take %d at %d!\n",p,t);
else last[p]=t;
}
}
return 0;
}
RC-u3
#include <bits/stdc++.h>
#define MAXN 100007
#define ll long long
using namespace std;
string in;
ll maxn,minn,pos,len;
ll n1,n2,sig,sum[MAXN];
int main() {
cin>>in; len=(ll)in.size();
if (in[0]=='-') pos++,sig=-1; else sig=1;
while (pos<len) {
n1=n2=0;
while (isdigit(in[pos])) n1=n1*10+in[pos]-'0',pos++;
if (in[pos]!='d') maxn+=sig*n1,minn+=sig*n1;
else {
pos++,n1=n1?n1:1;
while (isdigit(in[pos]) && pos<len) n2=n2*10+in[pos]-'0',pos++;
if (sig==1) maxn+=n1*n2,minn+=n1;
else maxn+=sig*n1,minn+=sig*n1*n2;
sum[n2]+=n1;
}
sig=(in[pos]=='+')?1:-1,pos++;
}
for (ll i=1;i<MAXN;i++)
if (sum[i]) printf("%lld %lld\n",i,sum[i]);
printf("%lld %lld",minn,maxn);
return 0;
}
RC-u4 攻略分队
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
struct group { int num,fl; bool a,b,c,dis; }g[7];
// a: MT b: worker c: leader
int sig,value=-INF;
vector<int> ans[2];
void dfs(int u) {
if (u>6) { // check answer
int mt[2]={0,0},worker[2]={0,0},leader[2]={0,0},val=0,sum[2]={0,0};
for (int i=1;i<=6;i++) {
if (g[i].dis) continue;
sum[g[i].fl]+=g[i].num;
mt[g[i].fl]+=g[i].a,worker[g[i].fl]+=g[i].b,leader[g[i].fl]+=g[i].c;
}
if (mt[0]>0 && mt[1]>0 && leader[0]>0 && leader[1]>0)
val=100000-abs(sum[0]-sum[1])*10-(sum[1]-sum[0]);
else if (leader[0]>0 && leader[1]>0) val=1000-abs(sum[0]-sum[1])*10-(sum[1]-sum[0]);
else val=-abs(sum[0]-sum[1])*10-(sum[1]-sum[0]);
if (val>value) {
value=val; ans[0].clear(); ans[1].clear();
for (int i=1;i<=6;i++) {
if (g[i].dis) continue;
ans[g[i].fl].push_back(i);
}
}
return;
}
g[u].fl=0,dfs(u+1); g[u].fl=1,dfs(u+1);
}
int main() {
for (int i=1;i<=6;i++) {
cin>>g[i].num;
if (g[i].num==0) g[i].dis=true;
}
for (int i=1;i<=6;i++) {
string in; cin>>in; sig+=in[0]-48;
g[i].a=(in[0]=='1')?true:false;
g[i].b=(in[1]=='1')?true:false;
g[i].c=(in[2]=='1')?true:false;
}
if (sig<2) { puts("GG"); return 0; }
dfs(1);
for (int i=0;i<(int)ans[0].size();i++) {
if (i!=(int)ans[0].size()-1) printf("%d ",ans[0][i]);
else printf("%d",ans[0][i]);
}
printf("\n");
for (int i=0;i<(int)ans[1].size();i++) {
if (i!=(int)ans[1].size()-1) printf("%d ",ans[1][i]);
else printf("%d ",ans[1][i]);
}
return 0;
}
RC-u5 树与二分图
#include <bits/stdc++.h>
#define MAXN 1000007
#define ll long long
using namespace std;
ll n,maxd,ans,pre1[MAXN],pre2[MAXN];
ll son[MAXN],dep[MAXN],sum[MAXN];
vector<int> G[MAXN];
void dfs(ll u) {
for (ll i=0;i<(ll)G[u].size();i++)
if (!dep[G[u][i]]) {
dep[G[u][i]]=dep[u]+1,sum[dep[G[u][i]]]++;
maxd=max(maxd,dep[G[u][i]]),son[u]++,dfs(G[u][i]);
}
}
int main() {
cin>>n;
for (ll i=1;i<n;i++) {
ll u,v; cin>>u>>v;
G[u].push_back(v),G[v].push_back(u);
}
dep[1]=sum[1]=1,dfs(1);
for (int i=1;i<=maxd;i++) {
if (i&1) pre1[i]=pre1[i-1]+sum[i],pre2[i]=pre2[i-1];
else pre1[i]=pre1[i-1],pre2[i]=pre2[i-1]+sum[i];
}
for (ll i=1;i<=maxd;i++) {
if (i&1) ans+=(sum[i]*(pre2[maxd]-pre2[i]));
else ans+=(sum[i]*(pre1[maxd]-pre1[i]));
}
//printf("ans = %lld\n",ans);
for (int i=1;i<=n;i++) ans-=son[i];
printf("%lld",ans);
return 0;
}
国赛
RC-u1
#include <bits/stdc++.h>
#define MAXN 10007
#define INF 0x3f3f3f3f
using namespace std;
int n,sred=INF,tred=0,vis=0;
int main() {
scanf("%d",&n);
for (int i=1;i<=n;i++) {
int now;
scanf("%d",&now);
if (now>=sred && now<tred && !vis) vis++,tred+=15;
else if (now>=tred) {
if(i!=1) printf("%d %d\n",sred,tred-1);
vis=0,sred=now+15,tred=now+45;
}
}
printf("%d %d",sred,tred-1);
return 0;
}
RC-u2
#include <bits/stdc++.h>
using namespace std;
struct Node {
int a,b,c,d;
bool operator < (const Node &T) const {
if (a!=T.a) return a<T.a;
if (b!=T.b) return b<T.b;
if (c!=T.c) return c<T.c;
else return d<T.d;
}
};
vector<Node> ans;
int pos[3][5],step[5],row,col,d1,d2;
int px[5],py[5],ux[5],uy[5];
inline bool check(int x,int y,int v) {
if (x<1 || x>5 || y<1 || y>5) return false;
if (y==pos[v][1] || y==pos[v][2] || x==pos[v][3] || x==pos[v][4])
return false;
return true;
}
int main() {
scanf("%d%d%d%d",&pos[1][1],&pos[1][2],&pos[1][3],&pos[1][4]);
for (int i=1;i<=4;i++) scanf("%d",&step[i]);
pos[1][3]-=step[3],pos[1][4]+=step[4];
pos[2][1]=pos[1][1]+step[1],pos[2][2]=pos[1][2]-step[2];
pos[2][3]=pos[1][3],pos[2][4]=pos[1][4];
scanf("%d%d%d%d",&row,&col,&d1,&d2);
for (int i=0;i<d2;i++) {
px[1]=row-d2+i,py[1]=col+i;
px[2]=row+i,py[2]=col+d2-i;
px[3]=row+d2-i,py[3]=col-i;
px[4]=row-i,py[4]=col-d2+i;
for (int j=1;j<=4;j++) {
if (!check(px[j],py[j],2)) continue;
for (int ii=0;ii<d1;ii++) {
ux[1]=px[j]-d1+ii,uy[1]=py[j]+ii;
ux[2]=px[j]+ii,uy[2]=py[j]+d1-ii;
ux[3]=px[j]+d1-ii,uy[3]=py[j]-ii;
ux[4]=px[j]-ii,uy[4]=py[j]-d1+ii;
for (int jj=1;jj<=4;jj++) {
if (!check(ux[jj],uy[jj],1)) continue;
ans.push_back(Node{ux[jj],uy[jj],px[j],py[j]});
}
}
}
}
sort(ans.begin(),ans.end());
for (int i=0;i<(int)ans.size();i++)
printf("%d %d %d %d\n",ans[i].a,ans[i].b,ans[i].c,ans[i].d);
return 0;
}
RC-u3
#include <bits/stdc++.h>
#define MAXN 1000007
#define ll long long
using namespace std;
ll n,m,k,p,s,t,v[MAXN],dp[MAXN],cnt[MAXN];
vector<ll> G[MAXN];
queue<ll> Q;
using namespace std;
int main() {
memset(cnt,0x3f,sizeof(dp));
scanf("%lld%lld%lld%lld",&n,&m,&k,&p);
for (ll i=1;i<=n;i++) scanf("%lld",&v[i]);
for (ll i=1;i<=m;i++) {
ll u,v; scanf("%lld%lld",&u,&v);
G[u].push_back(v),G[v].push_back(u);
}
scanf("%lld%lld",&s,&t);
Q.push(s),cnt[s]=1;
if (p==1) dp[s]=v[s];
while (!Q.empty()) {
ll now=Q.front(); Q.pop();
//printf("cnt[%lld] = %lld dp[%lld] = %lld\n",now,cnt[now],now,dp[now]);
for (ll i=0;i<(ll)G[now].size();i++) {
ll vt=G[now][i];
if (cnt[vt]<cnt[now]+1) continue;
else if (cnt[vt]==cnt[now]+1) {
if (cnt[vt]%k==0 && k==p) dp[vt]=max(dp[vt],dp[now]+v[vt]);
else if (cnt[vt]%k) dp[vt]=max(dp[vt],dp[now]+(cnt[vt]%k%p?0:v[vt]));
else dp[vt]=max(dp[vt],dp[now]);
}
else {
cnt[vt]=cnt[now]+1;
if (cnt[vt]%k==0 && k==p) dp[vt]=dp[now]+v[vt];
else if (cnt[vt]%k) dp[vt]=dp[now]+(cnt[vt]%k%p?0:v[vt]);
else dp[vt]=dp[now];
Q.push(vt);
}
}
}
printf("%lld",dp[t]);
return 0;
}
国赛的时候中午睡傻了,比赛的时候不紧不慢的,贼佛
最后全国排名 392,获二等奖一枚
感谢老师,监督半年没写代码的我参加比赛
标签:int,ll,实录,pos,MAXN,2022,sum,ROBCOM,define From: https://www.cnblogs.com/zhwer/p/16589821.html