28 条题解
-
2猫粮寸断 LV 10 @ 2017-10-18 21:24:24
//比较简单的模拟题,考察的是取模的应用 #include<iostream> using namespace std; int room[10002][102],pan[10002][102],lou[10002][102]; int main() { int n,m,i,k,ans=0,now,bian,sum=0; cin>>n>>m; for(i=1;i<=n;i++) { int has=0; for(k=0;k<m;k++) { cin>>pan[i][k]>>room[i][k]; if(pan[i][k]) { has++; lou[i][101]++; lou[i][has]=k; } } } cin>>now; for(i=1;i<=n;i++) { sum+=room[i][now]; sum%=20123; for(k=1;k<=lou[i][101];k++) if(lou[i][k]>=now) break; if(k>lou[i][101]) k=1; bian=(room[i][now]-1)%lou[i][101]; now=lou[i][(k+bian-1)%lou[i][101]+1]; } cout<<sum; return 0; }
-
12021-08-30 06:42:07@
#include<bits/stdc++.h> using namespace std; int a[10010][110],bk[10010][110],dd[10010][110],quan[10010]; int lm,n,m,ff,sum,nn=0; int main(){ cin>>n>>m; memset(a,0,sizeof(a)); for(int i=1; i<=n; i++) for(int j=0; j<m; j++){ cin>>bk[i][j]>>a[i][j]; quan[i]=quan[i]+bk[i][j]; } cin>>ff; for (int i=1; i<=n; i++){ sum=sum+a[i][ff]; lm=a[i][ff]; lm=lm%quan[i]+quan[i]; lm=lm-bk[i][ff]; while (lm>0){ ff++; ff=ff%m; lm=lm-bk[i][ff]; } } cout<<sum%20123; return 0; }
-
02021-02-25 12:27:33@
#include<bits/stdc++.h>
using namespace std;
int n,m,k,t,a[10002][102],b[10002][102],l,c[10002],d;
long long int ans;
int main()
{
//freopen("treasure.in","r",stdin);
//freopen("treasure.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>b[i][j]>>a[i][j];
if(b[i][j]==1)c[i]=c[i]+1;
}
}
cin>>k;l=k;
for(int i=1;i<=n;i++)
{
t=0;k=l;
ans=ans+a[i][k+1];
if(i==n)break;
d=a[i][k+1]%c[i];
if(d==0)
{
k=k-1;if(k<0)k=m-1;
while(b[i][k+1]==0)
{
k--;
if(k<0)k=m-1;
}
l=k;
}
if(b[i][k+1]==1)t=1;
while(t<d)
{
l++;
if(l==m)l=0;
if(b[i][l+1]==1)t++;
}
}
cout<<ans%20123;
} -
02017-11-04 20:07:49@
//从0开始!!!
var a,b:array[0..10005,0..105]of longint;
c:array[0..10005]of longint;
i,j,k,n,m,p,x,ans:longint;
begin
readln(n,m);
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
readln(a[i,j],b[i,j]);
inc(c[i],a[i,j]);
end;
readln(x);
for i:=0 to n-1 do
begin
ans:=(ans+b[i,x])mod 20123;
p:=b[i,x]mod c[i];
if p=0 then p:=c[i];
k:=x;
if a[i,k]=1 then dec(p);
while p>0 do
begin
inc(k);
k:=k mod m;
if a[i,k]=1 then dec(p);
end;
x:=k;
end;
ans:=ans mod 20123;
writeln(ans);
end. -
02017-08-22 03:04:11@
我的第40 AC 居然是 water question
#include<iostream> int a[10001][102],c,i,j,k,n,m,s,x; bool b[10001][101]; int main(){ scanf("%d%d",&n,&m); for (i=1;i<=n;++i) for (j=0;j<m;++j) { scanf("%d%d",&c,&a[i][j]); a[i][m]+=b[i][j]=c; } scanf("%d",&k); for (i=1;i<=n;++i) { x=a[i][k]; s=(s+x)%20123; x=(x-1)%a[i][m]+1; int y=0; while (y+=b[i][k],y<x) k=(k+1)%m; } printf("%d",s); return 0; }
-
02015-12-10 19:30:33@
此题需要注意的就是细节!!我第一次没取模,第二次取错模,第三次才对orz....
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define rep(i, x, y) for (int i = x; i <= y; ++i)using namespace std;
const int maxn = 10005, maxm = 105;
int n, m;
int hv[maxn][maxm], val[maxn][maxm];
bool vis[maxm];
int q[maxm], cnt;void calcu(int k, int now) {
memset(vis, 0, sizeof (vis));
cnt = 0;
for (int i = now; !vis[i]; i = (i + 1) % m) {
vis[i] = true;
if (hv[k][i]) q[cnt++] = i;
}
}
int main(int argc, const char *argv[]) {
scanf("%d %d", &n, &m);
rep(i, 0, n - 1) rep(j, 0, m - 1) scanf("%d %d", &hv[i][j], &val[i][j]);
int ans = 0, now;
scanf("%d", &now);
rep(i, 0, n - 1) {
ans += val[i][now];
ans %= 20123;
calcu(i, now);
now = q[(val[i][now] - 1) % cnt];
}
printf("%d\n", ans);
return 0;
} -
02015-10-31 11:59:29@
#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN = 10000 + 10;
const int MAXM = 100 + 10;
const int mod = 20123;int can[MAXN][MAXM], pos[MAXN][MAXM], quan[MAXN];
int main()
{
int n, m, now;
long long ans = 0;
scanf("%d%d", &n, &m);
for(int i=1; i<=n; i++)
for(int j=0; j<m; j++){
scanf("%d%d", &can[i][j], &pos[i][j]);
if(can[i][j]) quan[i]++;
}
scanf("%d", &now);
for(int i=1; i<=n; i++){
ans = (ans + pos[i][now])%mod;
int bri = 0, qiao;
while(pos[i][now] > quan[i])
pos[i][now] -= quan[i];
for(int j=now; bri<pos[i][now]; j=(j+1)%m)
if(can[i][j])
bri++, qiao = j;
now = qiao;
}
printf("%lld", ans);
return 0;
} -
02015-06-01 14:06:48@
program treasure;
Var
th:array[1..10000,1..100]of longint;
tl:array[1..10000,1..100]of 0..1;
xx:array[1..10000]of longint;
n,m,i,j,sum,k:longint;
procedure shang(x,y:longint);
var
a:longint;
begin
if(x=n+1)then exit;
a:=th[x,y];
sum:=(sum+a)mod 20123;
for j:=1 to m do
begin
th[x,j]:=th[x,j] mod xx[x];
if(th[x,j]=0)then th[x,j]:=xx[x];
end;
a:=th[x,y];
while(a<>0)do
begin
if(tl[x,y]=1)then dec(a);
if(a=0)then break;
inc(y);
if(y>m)then y:=y mod m;
end;
shang(x+1,y);
end;
Begin
fillchar(xx,sizeof(xx),0);
readln(n,m);
sum:=0;
for i:=1 to n do
begin
for j:=1 to m do
begin
read(tl[i,j],th[i,j]);
if(tl[i,j]=1)then inc(xx[i]);
end;
end;
read(k);
inc(k);
shang(1,k);
writeln(sum);
End. -
02014-10-25 19:10:54@
大部分时间都是花在读入上,getchar()大法好 //orzn+e
int F(int &n)
{
char ch,f=0;
while(((ch=getchar())<'0' || ch>'9') && ch!='-') ;
ch=='-'?n=f=0:(n=ch-'0',f=1);
while((ch=getchar())>='0'&&ch<='9') n*=10,n+=ch-'0';
return f?n:n=-n;
}
直接scanf
测试数据 #0: Accepted, time = 0 ms, mem = 9952 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 9944 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 9944 KiB, score = 10
测试数据 #3: Accepted, time = 46 ms, mem = 9948 KiB, score = 10
测试数据 #4: Accepted, time = 39 ms, mem = 9948 KiB, score = 10
测试数据 #5: Accepted, time = 483 ms, mem = 9944 KiB, score = 10
测试数据 #6: Accepted, time = 561 ms, mem = 9944 KiB, score = 10
测试数据 #7: Accepted, time = 546 ms, mem = 9948 KiB, score = 10
测试数据 #8: Accepted, time = 748 ms, mem = 9948 KiB, score = 10
测试数据 #9: Accepted, time = 748 ms, mem = 9948 KiB, score = 10
Accepted, time = 3171 ms, mem = 9952 KiB, score = 100
优化后
测试数据 #0: Accepted, time = 0 ms, mem = 9944 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 9948 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 9952 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 9952 KiB, score = 10
测试数据 #4: Accepted, time = 15 ms, mem = 9948 KiB, score = 10
测试数据 #5: Accepted, time = 78 ms, mem = 9948 KiB, score = 10
测试数据 #6: Accepted, time = 46 ms, mem = 9952 KiB, score = 10
测试数据 #7: Accepted, time = 93 ms, mem = 9944 KiB, score = 10
测试数据 #8: Accepted, time = 62 ms, mem = 9944 KiB, score = 10
测试数据 #9: Accepted, time = 93 ms, mem = 9948 KiB, score = 10
Accepted, time = 387 ms, mem = 9952 KiB, score = 100 -
02014-08-11 17:44:36@
program p1787;
var
a:array[0..10000,0..100,1..2]of longint;
b:array[0..100]of longint;
i,j,c,d,n,m,k,now,sum:longint;
begin
read(n,m);
for i:=1to n do
for j:=0to m-1do
read(a[i,j,1],a[i,j,2]);
read(now);
for i:=1to n do
begin
sum:=(sum+a[i,now,2])mod 20123;
d:=a[i,now,2];
k:=0;
for j:=now to m-1do
if a[i,j,1]=1then
begin
inc(k);
b[k]:=j;
end;
for j:=0to now-1do
if a[i,j,1]=1then
begin
inc(k);
b[k]:=j;
end;
d:=d mod k;
if d=0then
d:=k;
now:=b[d];
end;
write(sum);
end. -
02014-06-07 23:40:21@
C++党请注意本题数据太大使用cin会超时,请使用scanf
劝告:NOIP、NOI中遇到大数据请使用fscanf和fprintf
-
02013-10-20 16:56:39@
AC 相信党代表
program nihaowoshituerbi;
var
a:array[0..10000,0..100,1..2] of longint;
b:array[0..100] of longint;
i,j,c,d,n,m,k,now,sum:longint;
begin
read(n,m);
for i:=1 to n do
for j:=0 to m-1 do
read(a[i,j,1],a[i,j,2]);
read(now);for i:=1 to n do
begin
sum:=(sum+a[i,now,2]) mod 20123;
d:=a[i,now,2];
k:=0;
for j:=now to m-1 do
if a[i,j,1]=1 then begin inc(k);b[k]:=j;
end;
for j:=0 to now-1 do
if a[i,j,1]=1 then begin inc(k);b[k]:=j;
end;
d:=d mod k;
if d=0 then d:=k;
now:=b[d];end;
write(sum);
end. -
02013-08-21 14:40:42@
比赛的时候写过了
主要注意取余 否则会超时 -
02013-08-13 14:45:44@
刚才的不对,修改了一下:
#include <iostream>
using namespace std;
int a[10005][105],b[10005][105],shu[10005];
int main()
{
int i,j,k,n,m,c,x,ans=0;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%d%d",&a[i][j],&b[i][j]);
shu[i]+=a[i][j];
}
}
scanf("%d",&x);
for(i=0;i<n;i++){
ans+=b[i][x];
ans%=20123;
c=b[i][x]%shu[i];
if(c==0)c=shu[i];k=x;
if(a[i][k]==1)c--;
while(c>0){
k++;
k=k%m;
if(a[i][k]==1)c--;
}
x=k;
}
ans%=20123;
printf("%d",ans);
printf("\n");
return 0;
} -
02013-08-13 14:44:39@
#include <iostream>
using namespace std;
int a[10005][105],b[10005][105],shu[10005];
int main()
{
int i,j,k,n,m,c,x,ans=0;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%d%d",&a[i][j],&b[i][j]);
shu[i]+=a[i][j];
}
}
scanf("%d",&x);
for(i=0;i<n;i++){
ans+=b[i][x];
ans%=20123;
c=b[i][x]%shu[i];
if(c==0)c=shu[i];k=x;
if(a[i][k]==1)c--;
while(c>0){
k++;
k=k%m;
if(a[i][k]==1)c--;
}
x=k;
}
ans%=20123;
printf("%d",ans);
printf("\n");system("pause");
return 0;
}
(C++) -
02013-07-04 16:57:35@
看下那个地方错了,大婶们
type ds=record
f:0..1;
x:longint;
end;
var n,m,b:integer;
a:array[1..10000,0..99]of ds;
c:array[1..10000]of integer;
t:longint;
procedure init;
var i,j,s:integer;
begin
readln(n,m);
for i:=1 to n do
begin
s:=0;
for j:=0 to m-1 do
begin
readln(a[i,j].f,a[i,j].x);
s:=s+a[i,j].f;
end;
c[i]:=s;
end;
readln(b);
t:=0;
end;
procedure out;
begin
writeln(t);
end;
procedure work(floor,room:integer);
var i,j,k,tc:longint;
begin
i:=floor;j:=room;
k:=a[i,j].x;t:=(t+k) mod 20123;
k:=k mod c[i];
tc:=a[i,j].f;
while tc<k do
begin
inc(j);
if j=m then j:=0;
tc:=tc+a[i,j].f;
end;
if i<n then work(i+1,j);
end;
begin
init;
work(1,b);
out;
end. -
02012-11-24 17:41:23@
答案错误求改
program P1787;
var
n,m,i,j,l,k,now:integer;
s:longint;
a,b,c,d:array[1..10000,0..100] of longint;
e:array[1..10000] of integer;
begin
read(n,m);
for i:=1 to n do begin
for j:=0 to m-1 do begin
read(a,b);
if a=1 then begin e[i]:=e[i]+1; k:=k+1; c:=j; end;
end;
k:=0;
end;
readln(l);
now:=l;
s:=s+b[1,now];
for i:=1 to n-1 do begin
for j:=l to l+m do
if a[i,j mod m]=1 then begin l:=j mod m; break;end;
for j:=1 to e[i] do
if c=l then begin l:=j; break; end;
l:=(l+b-a) mod e[i];
now:=c;
s:=s+b;
l:=now;
end;
write(s mod 20123);
end.
全错 -
02012-11-22 17:13:42@
program treasure;
var
s:array[0..10000,0..100,1..2] of longint;
x:array[0..100] of longint;
a,b,c,d,n,m,k,now,sum:longint;
begin
{assign(input,'treasure.in');
reset(input);
assign(output,'treasure.out');
rewrite(output);}
read(n,m);
for a:=1 to n do
for b:=0 to m-1 do
read(s[a,b,1],s[a,b,2]);
read(now);for a:=1 to n do
begin
sum:=(sum+s[a,now,2]) mod 20123;
d:=s[a,now,2];
k:=0;
for b:=now to m-1 do
if s[a,b,1]=1 then begin inc(k);x[k]:=b;end;
for b:=0 to now-1 do
if s[a,b,1]=1 then begin inc(k);x[k]:=b;end;
d:=d mod k;
if d=0 then d:=k;
now:=x[d];end;
write(sum);
{close(input);
close(output);}
end. -
02012-11-21 20:06:39@
├ 测试数据 01:答案正确... (0ms, 8600KB)
├ 测试数据 02:答案正确... (15ms, 8600KB)
├ 测试数据 03:答案正确... (15ms, 8600KB)
├ 测试数据 04:答案正确... (15ms, 8600KB)
├ 测试数据 05:答案正确... (31ms, 8600KB)
├ 测试数据 06:答案正确... (323ms, 8600KB)
├ 测试数据 07:答案正确... (382ms, 8600KB)
├ 测试数据 08:答案正确... (383ms, 8600KB)
├ 测试数据 09:答案正确... (416ms, 8600KB)
├ 测试数据 10:答案正确... (426ms, 8600KB)---|---|---|---|---|---|---|---|-
Accepted / 100 / 2011ms / 8600KB├ 测试数据 01:答案正确... (102ms, 672KB)
├ 测试数据 02:答案正确... (0ms, 672KB)
├ 测试数据 03:答案正确... (13ms, 672KB)
├ 测试数据 04:答案正确... (0ms, 672KB)
├ 测试数据 05:答案正确... (15ms, 672KB)
├ 测试数据 06:答案正确... (15ms, 672KB)
├ 测试数据 07:答案正确... (13ms, 672KB)
├ 测试数据 08:答案正确... (15ms, 672KB)
├ 测试数据 09:答案正确... (15ms, 672KB)
├ 测试数据 10:答案正确... (15ms, 672KB)注意mod出0
还是没能秒杀啊 -
-12017-07-15 20:39:45@
额,对是对了,就是不知道为啥当mod得出0时为啥会这样处理的
Var
n,m,i,j,sum,num,l1,k,wz,k1:longint;
a,b:array[1..10000,0..100]of longint;
f:array[1..10000,1..100]of longint;
l:array[1..10000]of longint;
Begin
readln(n,m);
for i:=1 to n do
for j:=0 to m-1 do
begin
read(a[i,j]);
if a[i,j]=1 then
begin
inc(l[i]);
f[i,l[i]]:=j;
end;
readln(b[i,j]);
end;
readln(k);
l1:=1;
while l1<=n do
begin
num:=(num+b[l1,k]) mod 20123;
if b[l1,k] mod l[l1]=0 then
sum:=l[l1]
else
sum:=b[l1,k] mod l[l1];
wz:=0;
while wz<sum do
begin
if a[l1,k]=1 then
inc(wz);
if k=m-1 then
k:=0
else
inc(k);
end;
if k=0 then
k:=m-1
else
dec(k);
inc(l1);
end;
writeln(num);
readln;
End.