HDOJ 4915 Multiplication table, hdoj4915
You can determine the numbers 0 and 1, and then count the number of dozens on each line ....
It seems that I have passed the case of not considering 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 DescriptionTeacher 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.
It's guaranteed the solution is unique.
InputThere 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!
OutputFor 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.
Sample Input
42 3 1 1 3 2 1 01 1 1 1 1 1 1 13 2 1 1 3 1 1 21 0 1 1 1 2 1 30
Sample Output
Case #1: 1 3 2 0
Authorxudyh
Source2014 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;}