hdu 4951

Multiplication table

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 435    Accepted Submission(s): 204

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.

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!

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.

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

Source

2014 Multi-University Training Contest 8

Recommend

hujie   |   We have carefully selected several similar problems for you:  4955 4954 4953 4952 4950

分析:大水题,,,要敢于分析。。。

详见题解:http://blog.sina.com.cn/u/1809706204

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<cstdio>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<map>
 9
10 #define N 1005
11 #define M 15
12 #define mod 1000000007
13 #define mod2 100000000
14 #define ll long long
15 #define maxi(a,b) (a)>(b)? (a) : (b)
16 #define mini(a,b) (a)<(b)? (a) : (b)
17
18 using namespace std;
19
20 int cnt;
21 int p;
22 int i,j;
23 int a[N][N];
24 int c[N][N];
25 int cc[N];
26 int ans[N];
27
28 int main()
29 {
30     //ini();
31     //freopen("data.in","r",stdin);
32     //scanf("%d",&T);
33     //for(int cnt=1;cnt<=T;cnt++)
34     //while(T--)
35     cnt=1;
36     while(scanf("%d",&p)!=EOF)
37     {
38         if(p==0) break;
39         printf("Case #%d:",cnt);cnt++;
40         memset(c,0,sizeof(c));
41         memset(cc,0,sizeof(cc));
42        for(i=0;i<p;i++)
43        {
44            for(j=1;j<=p;j++){
45                 scanf("%d",&a[i][2*j-1]);
46                 cc[ a[i][2*j-1] ]++;
47                 scanf("%d",&a[i][2*j]);
48                 cc[ a[i][2*j] ]++;
49            }
50        }
51
52        int ma=cc[0];
53        int index=0;
54        for(i=0;i<p;i++){
55             if(cc[i]>ma){
56                 ma=cc[i];index=i;
57             }
58        }
59        ans[0]=index;
60
61        memset(cc,0,sizeof(cc));
62
63        for(i=0;i<p;i++)
64        {
65            for(j=1;j<=p;j++){
66                 if(c[i][ a[i][2*j-1] ]==0){
67                     c[i][ a[i][2*j-1] ]=1;
68                     cc[i]++;
69                 }
70            }
71            if(cc[i]==1){
72                 if(ans[0]!=i) ans[1]=i;
73            }
74            else{
75                 ans[ cc[i] ]=i;
76            }
77        }
78
79        for(i=0;i<p;i++) printf(" %d",ans[i]);
80        printf("\n");
81     }
82
83
84
85     return 0;
86 }

hdu 4951

时间: 2024-11-09 00:56:56

hdu 4951的相关文章

2014多校联合八(HDU 4945 HDU 4946 HDU 4948 HDU 4950 HDU 4951 HDU 4952)

HDU 4945 2048 题意:给你一堆数字  问有几个子集可以拼出2048 思路: 拼数字的规则相当于让数字乘二  所以不是2^i的数字不会拼出2048  那么这些数可选可不选  即为2^cnt种可能 之后只要计算出有几个子集不可能拼出2048即可  不过简单的直接dp是2048*100000的复杂度的  会TLE 所以要变成先枚举元素  再枚举该种元素个数  再枚举2048种状态  然后利用组合求(组合里需要逆元) 为什么这样快?  因为比如枚举2^5这个元素的时候  最多取2^6个  枚

hdu 4951 乘法表

http://acm.hdu.edu.cn/showproblem.php?pid=4951 依照我原先的想法是 先找出ans[0] 和ans[1]来,这个好找吧,要是有一行全部是相等的数组成那这行的序号就是ans[0], 要是有一[i,j],i*j=ans[0] i ,那么ans[j]=1,  找到了ans[0]和ans[1] ,然后根据已知的遍历推算出其他的结果. 1 #include<iostream> 2 #include<cstdio> 3 #include<map

HDU 4951 Multiplication table 数论

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

多第八田间学校:几何+图论出度+模拟+找到规律

HDU 4946 pid=1002&cid=509" style="color:rgb(26,92,200); text-decoration:none; font-family:Tahoma; background-color:rgb(215,235,255)">Area of Mushroom 这题WA了7发才过,队友做的,然后一起debug了好久. 刚開始是没排序. 然后是在同一个位置的点没有处理好. 然后把这两个问题搞定就A了. #include <

HDU 1170

Balloon Comes! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4951    Accepted Submission(s): 1589 Problem Description The contest starts now! How excited it is to see balloons floating around

HDU 4902 Nice boat(数据结构-线段树)

Nice boat Problem Description There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and c

HDU Multiplication table 阅读题

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4951 题意:给一个P进制的乘法表,行和列分别代表0~p-1,第i行第j*2+1和第j*2+2列代表的是第i行的数x和第j列的数的乘积,不过这个乘法表被人弄乱了,原来的0~p-1被映射到了一个新的0~p-1的permutation(以前在CF上看见的permutation表示1~P,所以稍有迷茫),分别代表了新的不同的数,乘法表上的数也都被映射了.现在要找出映射到了什么新的数. 思路:毫无疑问,出现最多的

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;

HDU 5542 The Battle of Chibi dp+树状数组

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:给你n个数,求其中上升子序列长度为m的个数 可以考虑用dp[i][j]表示以a[i]结尾的长度为j的上升子序列有多少 裸的dp是o(n2m) 所以需要优化 我们可以发现dp的第3维是找比它小的数,那么就可以用树状数组来找 这样就可以降低复杂度 #include<iostream> #include<cstdio> #include<cstring> #include