1 条题解
-
0
C++ :
#include <cstdio> #include <iostream> using namespace std; long long n,m,a[10001][101],b[10001][101],c[10001],sum,k,ans,q; int main() { scanf("%lld%lld",&n,&m); for (int i=1;i<=n;i++) for (int j=0;j<=m-1;j++) { scanf("%lld%lld",&a[i][j],&b[i][j]); c[i]+=a[i][j]; //c[i]记录第i层楼梯总数 } scanf("%lld",&k); for (int j=1;j<=n;j++) { sum+=b[j][k]; //记录答案 ans=0; q=k; b[j][q]=(b[j][q]-1)%c[j]+1; //减去多余部分 while (ans<b[j][q]) { ans+=a[j][k]; //如上 if (ans==b[j][q]) break; k++; if (k==m) k=0; } } printf("%lld\n",sum%20123); //输出(别忘了%20123) }
Java :
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int x[][]=new int[n][m]; int flat[][]=new int[n][m]; //是否有楼梯数组 for(int i=0;i<n;i++) for(int j=0;j<m;j++) { flat[i][j]=sc.nextInt(); x[i][j]=sc.nextInt(); } int t=sc.nextInt(); //从t号房间开始 long s=0; for(int i=0;i<n;i++) { s+=x[i][t]; //s为每层第一个房间的x的和 int a=0,b=0; for(int j=0;j<m;j++) { if(flat[i][j]==1) // 查询这层有楼梯的房间存到a a++; } b=x[i][t]%a; //用求余去掉x重复循环的时间 if(b==0) //当余数为0时,x为a的倍数 所以直接b=a b=a; for(int j=t;j<m;j++) { //从t开始找出有楼梯的房间 if(flat[i][j]==1) b--; if(b==0) { t=j; //每层第一个房间号为t break; } if(j==m-1) //索引到最后一个数时 回到开头 j=-1; } } System.out.println(s%20123); } }
- 1
信息
- ID
- 1261
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者