首页 > 代码库 > HDOJ 4915 Multiplication table
HDOJ 4915 Multiplication table
可以特判出0和1,再统计每行出现了多少种十位上的数就可以了....
没有考虑2的情况似乎也过了......
Multiplication table
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 800 Accepted Submission(s): 360
Problem Description
Teacher Mai has a multiplication table in base p.
For example, the following is a multiplication table in base 4:
* 0 1 2 3
0 00 00 00 00
1 00 01 02 03
2 00 02 10 12
3 00 03 12 21
But a naughty kid maps numbers 0..p-1 into another permutation and shuffle the multiplication table.
For example Teacher Mai only can see:
1*1=11 1*3=11 1*2=11 1*0=11
3*1=11 3*3=13 3*2=12 3*0=10
2*1=11 2*3=12 2*2=31 2*0=32
0*1=11 0*3=10 0*2=32 0*0=23
Teacher Mai wants you to recover the multiplication table. Output the permutation number 0..p-1 mapped into.
It‘s guaranteed the solution is unique.
For example, the following is a multiplication table in base 4:
0 00 00 00 00
1 00 01 02 03
2 00 02 10 12
3 00 03 12 21
But a naughty kid maps numbers 0..p-1 into another permutation and shuffle the multiplication table.
For example Teacher Mai only can see:
3*1=11 3*3=13 3*2=12 3*0=10
2*1=11 2*3=12 2*2=31 2*0=32
0*1=11 0*3=10 0*2=32 0*0=23
Teacher Mai wants you to recover the multiplication table. Output the permutation number 0..p-1 mapped into.
It‘s guaranteed the solution is unique.
Input
There are multiple test cases, terminated by a line "0".
For each test case, the first line contains one integer p(2<=p<=500).
In following p lines, each line contains 2*p integers.The (2*j+1)-th number x and (2*j+2)-th number y in the i-th line indicates equation i*j=xy in the shuffled multiplication table.
Warning: Large IO!
For each test case, the first line contains one integer p(2<=p<=500).
In following p lines, each line contains 2*p integers.The (2*j+1)-th number x and (2*j+2)-th number y in the i-th line indicates equation i*j=xy in the shuffled multiplication table.
Warning: Large IO!
Output
For each case, output one line.
First output "Case #k:", where k is the case number counting from 1. The following are p integers, indicating the permutation number 0..p-1 mapped into.
First output "Case #k:", where k is the case number counting from 1. The following are p integers, indicating the permutation number 0..p-1 mapped into.
Sample Input
4 2 3 1 1 3 2 1 0 1 1 1 1 1 1 1 1 3 2 1 1 3 1 1 2 1 0 1 1 1 2 1 3 0
Sample Output
Case #1: 1 3 2 0
Author
xudyh
Source
2014 Multi-University Training Contest 8
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <set> using namespace std; int nextInt() { char ch; int ret=0; while(ch=getchar()) { if(ch>='0'&&ch<='9') { ret=ret*10+ch-'0'; } else break; } return ret; } int n,f[510][1010],ans[550],cas=1; bool v1[510],v2[510]; int s1,s2; int main() { while(scanf("%d",&n)!=EOF&&n) { getchar(); for(int i=0;i<n;i++) { s1=0; s2=0; for(int j=0;j<n;j++) v1[j]=v2[j]=true; for(int j=0;j<n;j++) { int num1=nextInt(); int num2=nextInt(); if(v1[num1]) { s1++; v1[num1]=0; } if(v2[num2]) { s2++; v2[num2]=0; } } int diff1=s1; int diff2=s2; if(diff1==1) { if(diff2==1) ans[0]=i; else ans[1]=i; } else { int d=diff1; ans[d]=i; } } printf("Case #%d:",cas++); for(int i=0;i<n;i++) { printf(" %d",ans[i]); } putchar(10); } return 0; }
HDOJ 4915 Multiplication table
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。