以下两份代码:
差别只有中间的
to[t][st] = to[t][st]%have[t]+have[t]
和
to[t][st] = to[t][st]%have[t];
但后者只有十分,前者能拿满分。
请问有人知道是为什么吗?
两份代码如下:
#include<bits/stdc++.h>
using namespace std;
const int mod = 20123;
int N,M,have[10010],ans,to[10010][110],now;
bool is[10010][110];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> N >> M;
for(int i = 1;i <= N;++i){
for(int j = 0;j < M;++j){
cin >> is[i][j] >> to[i][j];
if(is[i][j]) have[i]++;
}
}
cin >> now;
for(int t = 1;t <= N;++t){
ans = (ans+to[t][now])%mod;
int st = now;
if(is[t][now]) to[t][st]--;
to[t][st] = to[t][st]%have[t];
//to[t][st] = to[t][st]%have[t]+have[t]
while(to[t][st]){
now = (now+1)%M;
if(is[t][now]) to[t][st]--;
}
}
cout << ans;
return 0;
}
这份只有十分(AC on 1)
#include<bits/stdc++.h>
using namespace std;
const int mod = 20123;
int N,M,have[10010],ans,to[10010][110],now;
bool is[10010][110];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> N >> M;
for(int i = 1;i <= N;++i){
for(int j = 0;j < M;++j){
cin >> is[i][j] >> to[i][j];
if(is[i][j]) have[i]++;
}
}
cin >> now;
for(int t = 1;t <= N;++t){
ans = (ans+to[t][now])%mod;
int st = now;
if(is[t][now]) to[t][st]--;
//to[t][st] = to[t][st]%have[t];
to[t][st] = to[t][st]%have[t]+have[t]
while(to[t][st]){
now = (now+1)%M;
if(is[t][now]) to[t][st]--;
}
}
cout << ans;
return 0;
}
这份满分