/ Vijos / 题库 / 寻宝 /

26 条题解

• @ 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;
}
``````
• @ 2017-10-18 21:27:01

开始操作

• @ 2017-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
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
inc(c[i],a[i,j]);
end;
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.

• @ 2017-11-04 20:10:13

哇好厉害

• @ 2017-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;
}
``````
• @ 2015-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;
}

• @ 2015-12-10 19:31:48

顺便说一句，为什么最近Vj测评机总是挂......

• @ 2015-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;
}

• @ 2015-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);
sum:=0;
for i:=1 to n do
begin
for j:=1 to m do
begin
if(tl[i,j]=1)then inc(xx[i]);
end;
end;
inc(k);
shang(1,k);
writeln(sum);
End.

• @ 2014-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

• @ 2014-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
for i:=1to n do
for j:=0to m-1do
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.

• @ 2014-06-07 23:40:21

C++党请注意本题数据太大使用cin会超时，请使用scanf

劝告：NOIP、NOI中遇到大数据请使用fscanf和fprintf

• @ 2013-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
for i:=1 to n do
for j:=0 to m-1 do

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.

• @ 2013-08-21 14:40:42

比赛的时候写过了
主要注意取余 否则会超时

• @ 2013-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;
}

• @ 2013-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++)

• @ 2013-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
for i:=1 to n do
begin
s:=0;
for j:=0 to m-1 do
begin
s:=s+a[i,j].f;
end;
c[i]:=s;
end;
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.

• @ 2012-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

for i:=1 to n do   begin

for j:=0 to m-1 do begin

if a=1 then begin e[i]:=e[i]+1; k:=k+1; c:=j; end;

end;

k:=0;

end;

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.

全错

• @ 2013-10-20 17:14:15

if k=0 then ......

• @ 2012-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);}

for a:=1 to n do

for b:=0 to m-1 do

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.

• @ 2012-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

还是没能秒杀啊

• @ 2017-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
for i:=1 to n do
for j:=0 to m-1 do
begin
if a[i,j]=1 then
begin
inc(l[i]);
f[i,l[i]]:=j;
end;
end;
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);
End.

• @ 2017-02-16 18:34:56

注意不能用 cin
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;

int ti[10002][102],pai[10002][102],one[10002];
int main(){
//freopen("treasure.in","r",stdin);
// freopen("treasure.out","w",stdout);
int n,m,k,sum=0;
scanf("%d %d",&n,&m);

for(int i=1;i<=n;i++)
for(int j=0;j<=m-1;j++){
scanf("%d %d",&ti[i][j],&pai[i][j]);
if(ti[i][j]==1) ++one[i];
}

scanf("%d",&k);

for(int i=1;i<=n;){
int a=pai[i][k];
sum=(sum%20123+a%20123)%20123;
a=pai[i][k]%one[i];
if(a==0) a=one[i];

// printf("%d\n",sum);
for(int j=k;;j++){

if(ti[i][j]==1) --a;
if(a==0){
//printf("第%d层 第%d间 \n",i,j);
k=j;i+=1;

break;
}
if(j==m-1) j=-1;
}
}
printf("%d",sum);

return 0;
}

• @ 2016-09-04 22:00:26

这题目贼噶坑的啊！！！我理解就花了好久
var
a,b:array[0..10000,0..100]of longint;
x,y,i,j,n,m,s,t:longint;
c:array[1..10000]of longint;
begin
for i:=1 to n do begin
s:=0;
for j:=0 to m-1 do begin
if a[i,j]=1 then s:=s+1;
end;
c[i]:=s;
end;
s:=0;
for i:=1 to n do begin
y:=x;
s:=(s+b[i,x])mod 20123;
t:=b[i,x]mod c[i]+c[i];
repeat
if a[i,y]=1 then t:=t-1;
if t=0 then break;
y:=y+1;
if y=m then y:=0;
until false;
x:=y;
end;
write(s);
end.
点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点
点点点点点点点点点点点点点点点点点点点点点点点点点点点点赞赞赞赞点点点
点点点点点点点点点点点点点点点点点点点点点点点点赞赞赞赞赞赞赞赞赞点点
点点点点点点点点点点点点点点点点点点赞赞赞赞赞赞赞赞赞赞赞赞赞赞赞点点
点点点点点点点点点点点点点点点点赞赞赞赞赞赞赞赞赞赞赞赞赞赞赞点点点点
点点点点点点点点点点点赞赞赞赞点赞赞赞赞赞赞赞赞赞赞赞点点点点点点点点
点点点点点点点点赞赞赞赞赞赞赞点赞赞赞点点赞赞赞赞赞点点点点点点点点点
点点点赞赞赞赞赞赞赞赞赞赞赞赞点点点点点点赞赞赞赞点点点点点点点点点点
点赞赞赞赞赞赞赞赞赞赞赞赞赞赞点点点点点点赞赞赞赞点点点点点点点点点点
点赞赞赞赞赞赞赞赞赞赞赞赞点点点点点点点赞赞赞赞赞赞赞赞赞赞赞点点点点
点赞赞赞赞赞赞赞赞赞赞赞赞点点点点点点赞赞赞赞赞赞赞赞赞赞赞赞赞赞点点
点点赞赞赞赞赞赞赞赞赞赞点点点点点赞赞赞赞赞赞点点点赞赞赞赞赞赞赞点点
点点点点点点点点赞赞赞赞点点点点点赞赞赞赞点点点点点点赞赞赞赞赞点点点
点点点点点点点点赞赞赞赞点点点点赞赞赞赞点点赞赞点点点赞赞赞赞赞点点点
点点点点点点点点赞赞赞赞点点点点赞赞赞赞点点赞赞赞赞点赞赞赞赞赞点点点
点点点点点点点点赞赞赞赞点点点点赞赞赞赞点点赞赞赞赞点赞赞赞赞赞点点点
点点点点点点点点赞赞赞赞点点点点赞赞赞赞点点赞赞赞点点赞赞赞赞赞点点点
点点点点点点点点赞赞赞赞点点点点赞赞赞赞点点赞赞赞点点赞赞赞赞赞点点点
点点点点点点点点赞赞赞赞点点点点赞赞赞赞点赞赞赞赞点点赞赞赞赞赞点点点
点点点点点点点点赞赞赞赞点点点点赞赞赞赞点赞赞赞赞点点赞赞赞赞赞点点点
点点点点点点点点赞赞赞赞点点点点赞赞赞赞点赞赞赞赞点点赞赞赞赞赞点点点
点点点点点点点点赞赞赞赞点点点点赞赞赞赞点赞赞赞赞点点赞赞赞赞赞点点点
点点点点点点点点赞赞赞赞点点点点赞赞赞点点赞赞赞赞点点赞赞赞赞赞点点点
点点赞赞点点点赞赞赞赞赞点点点点赞赞赞点点赞赞赞点点点赞赞赞赞赞点点点
点点赞赞赞赞赞赞赞赞赞赞点点点点点赞赞点点赞赞点点点点赞赞赞赞赞点点点
点点点赞赞赞赞赞赞赞赞赞点点点点点点点点赞赞赞点点点点赞赞赞赞点点点点
点点点点点赞赞赞赞赞赞赞点点点点点点点点赞赞赞点赞赞赞赞点点点点点点点
点点点点点点赞赞赞赞赞赞点点点点点点点赞赞赞赞点点赞赞赞赞点点点点点点
点点点点点点点点点赞赞赞点点点点点点赞赞赞赞赞点点点赞赞赞赞赞点点点点
点点点点点点点点点点点点点点点点赞赞赞赞赞赞点点点点点赞赞赞赞赞赞点点
点点点点点点点点点点点点点点点赞赞赞赞赞赞点点点点点点赞赞赞赞赞赞赞点
点点点点点点点点点点点点点点赞赞赞赞赞点点点点点点点点点赞赞赞赞赞赞点
点点点点点点点点点点点点点赞赞赞赞赞点点点点点点点点点点点赞赞赞赞赞点
点点点点点点点点点点点点赞赞赞点点点点点点点点点点点点点点点赞赞赞点点
点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点

ID
1787

7

2623

605

23%

5