2 solutions
-
1
模拟( 50pts)
- 从小往上模拟每层走法。
#include<bits/stdc++.h> using namespace std; const int N=10010,M=110,MOD=20123; bool st[N][M]; int x[N][M]; int main() { int n,m,k; cin>>n>>m; int res=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cin>>st[i][j]>>x[i][j]; } } cin>>k; for(int i=0;i<n;i++) { int t=x[i][k]; res=(res+t)%MOD; //累加答案 for(int j=k;;j=(j+1)%m) //模拟走法 { if(st[i][j]) //有楼梯 { if(--t==0) //找到了第t个楼梯 { k=j; //从编号为j的楼梯继续往上 break; } } } } cout<<res<<endl; return 0; }
模拟优化(100pts)
- 由于每层楼梯只有100个房间,那么我们可以去除周期以后再进行模拟。
#include<bits/stdc++.h> using namespace std; const int N=10010,M=110,MOD=20123; bool st[N][M]; int x[N][M]; int main() { int n,m,k; cin>>n>>m; int res=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cin>>st[i][j]>>x[i][j]; } } cin>>k; for(int i=0;i<n;i++) { int s=0; for(int j=0;j<m;j++) { if(st[i][j]) { s++; } } int t=x[i][k]; res=(res+t)%MOD; //累加答案 t=t%s; //去掉周期 if(!t) t=s; //整数周期,也就是到最后一个有楼梯的房间 for(int j=k;;j=(j+1)%m) //模拟走法 { if(st[i][j]) //有楼梯 { if(--t==0) //找到了第t个楼梯 { k=j; //从编号为j的楼梯继续往上 break; } } } } cout<<res<<endl; return 0; }
- 1
Information
- ID
- 438
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 10
- Tags
- # Submissions
- 4
- Accepted
- 2
- Uploaded By