RC-u1 不要浪费金币
模拟 AC:
#include<iostream>
#define int long long
using namespace std;
const int N=1e3+5;
int n,m,p[N],ans;
signed main(){
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>p[i];
int sum=0;
for(int i=1;i<=n;i++){
if(sum+p[i]<=m) sum+=p[i];
else {
sum=p[i];
ans++;
}
}
cout<<ans<<endl;
return 0;
}
RC-u2 智能服药助手
未AC (9/15):
#include<iostream>
#include<cstring>
using namespace std;
const int N=1005;
int n,m,T[N],flag[N];
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>T[i];
memset(flag,-0x3f,sizeof(flag));
while(m--){
int t,k;
cin>>t>>k;
while(k--){
int x;
cin>>x;
if(t-flag[x]<T[x]) printf("Don't take %d at %d!\n",x,t);
else flag[x]=t;
}
}
return 0;
}
RC-u3 跑团机器人
模拟 AC:
#include<iostream>
#include<cstring>
#include<map>
#define int long long
using namespace std;
const int N=2e4+5;
string s0,ss,s;
int flag[N],idx,maxx,minn;
map<int,int>mapp;
signed main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>s0;
if(s0[0]!='-') ss+="+";
ss+=s0;
int len=ss.size();
int temp=0;
for(int i=0;i<len;i++){
if(ss[i]=='d'){
if(ss[i-1]=='+'){
temp=1;
s=ss.substr(0,i);
s+="1";
s+=ss.substr(i,len);
}
if(ss[i-1]=='-'){
temp=1;
s=ss.substr(0,i);
s+="1";
s+=ss.substr(i,len);
}
}
}
if(temp==0) s+=ss;
for(int i=0;i<s.size();i++){
if(s[i]=='+') flag[idx++]=i;
if(s[i]=='-') flag[idx++]=i;
}
flag[idx++]=s.size();
for(int i=0;i<idx-1;i++){
int l=flag[i],r=flag[i+1];
int key=-1;
for(int j=l;j<r;j++) if(s[j]=='d') {key=j;break;}
if(key==-1){
int sum=0;
for(int j=l+1;j<r;j++){
sum*=10;
int t=s[j]-'0';
sum+=t;
}
if(s[l]=='+') {minn+=sum;maxx+=sum;}
else {minn-=sum;maxx-=sum;}
}
else{
int a=0,b=0;
for(int j=l+1;j<key;j++){
a*=10;
int t=s[j]-'0';
a+=t;
}
for(int j=key+1;j<r;j++){
b*=10;
int t=s[j]-'0';
b+=t;
}
if(s[l]=='+') {minn+=a;maxx+=a*b;}
else {minn-=a*b;maxx-=a;}
if(mapp.count(b)==0) mapp[b]=a;
else mapp[b]+=a;
}
}
for(auto x:mapp) cout<<x.first<<" "<<x.second<<endl;
cout<<minn<<" "<<maxx<<endl;
return 0;
}