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
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  4955 4954 4953 4952 4950 
 
分析:大水题,,,要敢于分析。。。
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map> #define N 1005
#define M 15
#define mod 1000000007
#define mod2 100000000
#define ll long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int cnt;
int p;
int i,j;
int a[N][N];
int c[N][N];
int cc[N];
int ans[N]; int main()
{
//ini();
//freopen("data.in","r",stdin);
//scanf("%d",&T);
//for(int cnt=1;cnt<=T;cnt++)
//while(T--)
cnt=;
while(scanf("%d",&p)!=EOF)
{
if(p==) break;
printf("Case #%d:",cnt);cnt++;
memset(c,,sizeof(c));
memset(cc,,sizeof(cc));
for(i=;i<p;i++)
{
for(j=;j<=p;j++){
scanf("%d",&a[i][*j-]);
cc[ a[i][*j-] ]++;
scanf("%d",&a[i][*j]);
cc[ a[i][*j] ]++;
}
} int ma=cc[];
int index=;
for(i=;i<p;i++){
if(cc[i]>ma){
ma=cc[i];index=i;
}
}
ans[]=index; memset(cc,,sizeof(cc)); for(i=;i<p;i++)
{
for(j=;j<=p;j++){
if(c[i][ a[i][*j-] ]==){
c[i][ a[i][*j-] ]=;
cc[i]++;
}
}
if(cc[i]==){
if(ans[]!=i) ans[]=i;
}
else{
ans[ cc[i] ]=i;
}
} for(i=;i<p;i++) printf(" %d",ans[i]);
printf("\n");
} return ;
}

hdu 4951的更多相关文章

  1. HDU 4951 Multiplication table 阅读题

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4951 题意:给一个P进制的乘法表.行和列分别代表0~p-1,第i行第j*2+1和第j*2+2列代表的是第i ...

  2. HDU 4951 Multiplication table(2014 Multi-University Training Contest 8)

    思路   如果进制为p    那么当x<p时 (p-1)*(p-x)=(p-(x+1))  *p +x     因为x<p  所以没有进位  所以高位上的数字为    p-(x+1). 根 ...

  3. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  5. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  6. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  8. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  9. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. UVA - 12264 Risk (二分,网络流)

    题意比较坑,移动完以后的士兵不能再次移动,不然样例都过不了... 最小值最大满足决策单调性所以二分答案,跑网络流验证是否可行. 这种题重点在建图,为了保证只移动一次,拆点,一个入点一个出点,到了出点的 ...

  2. python常用模块之requests

    一.requests 1.GET   url带参数请求 >>> payload = {'key1': 'value1', 'key2': 'value2'} >>> ...

  3. 响应式Web设计- Viewport

    什么是Viewport? viewport是用户网页的可视区域, 翻译为中文可以叫做"视区". 设置Viewport 一个常用的针对移动网页优化过的页面的Viewport meta ...

  4. 同时使用多个UITableView

    1.xib\storyboard中给2个tableView设置constraints(等宽) 方法 : ①设置mainTableView的上\下\左\三部分的约束为0:subTableView上\下\ ...

  5. JS添加验证页面中script标签中是否存在jquery文件

    window.onload = function() { var al = document.getElementsByTagName("script"); var new_ele ...

  6. 洛谷 P1483 序列变换

    https://www.luogu.org/problemnew/show/P1483 数据范围不是太大. 一个数组记录给k,记录每个数加了多少. 对于查询每个数的大小,那么就枚举每个数的因子,加上这 ...

  7. HDU-1241-油藏

    这题一道深搜的简单题目,其实题目的思路就只是向八个方向搜索,然后把整个油田遍历一遍即可. #include <cstdio> #include <cstring> int ma ...

  8. [LUOGU] P4767 [IOI2000]邮局

    https://www.luogu.org/problemnew/show/P4767 四边形不等式好题! 可以设f[i][j]表示前i个村庄,建了j个邮局的最小代价. 转移:f[i][j]=min{ ...

  9. GIMP的Path用法,快速选区

    1/很多的快捷键,不多就Shift Ctrl Alt可以自由选择,这里自己多试几次可以熟练掌握吧. 2/快速选区作为Path,这里颜色要纯一点好:Selection to Path Step1:选择F ...

  10. Java学习经验

    随着Java学习的深入,越来越感觉记笔记的重要性,一方面可以使自己更加善于总结,提高对项目和自己的认知,另一方面可以让知识条例更加鲜明,并且加深对知识点的记忆.Java是一门很早开始兴起的语言,用途非 ...