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
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 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!
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.
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
#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的更多相关文章
- 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 ...
- 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). 根 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
随机推荐
- HTML5 Geolocation(地理位置)
HTML5 Geolocation(地理位置).是用来定位用户的位置的. HTML5 Geolocation API 用于获得用户的地理位置,鉴于该特性可能侵犯用户的隐私权,除非用户同意,否则不能获取 ...
- 获得Java中System对应一些属性值
public static void main(String[] args){ System.out.println("Java运行时环境版本:\n"+System.getProp ...
- 随机生成一份试卷,试卷的种类分为单选、多选、判断三种题型。nodejs6.0 mysql
背景:从数据库中,随机生成一份试卷,试卷的种类分为单选.多选.判断三种题型. 首先我需要生成随机数id(在这之前我需要知道数据库中各个题型的题数,这样我才能设置随机数),并依据生成的随机数id,去查找 ...
- UVa-156-反片语
这题比较精妙的是,我们对于单词重排,实际上是进行了标准化的处理,即按照字典序排序. 这样的话,就很方便地处理了单词的重排问题,我们不需要使用全排列函数进行排列尝试,我们直接化简为一,然后进行比较就可以 ...
- GIMP的Path用法,快速选区
1/很多的快捷键,不多就Shift Ctrl Alt可以自由选择,这里自己多试几次可以熟练掌握吧. 2/快速选区作为Path,这里颜色要纯一点好:Selection to Path Step1:选择F ...
- 在已编译安装nginx上动态添加模块
一.添加nginx模块 找到安装nginx的源码根目录,如果没有的话下载新的源码 wget http://nginx.org/download/nginx-1.8.1.tar.gz 查看ngixn版本 ...
- $(addprefix PREFIX,NAMES…)
addprefix 是makefile中的函数,是添加前缀的函数例如:$(addprefix src/,foo bar) 返回值为“src/foo src/bar”.所以上面的意思是为dirver_d ...
- WIN10配置JDK
系统变量→新建 JAVA_HOME 变量 变量值填写jdk的安装目录(本人是 E:\Java\jdk1.7.0) 系统变量→寻找 Path 变量→编辑 在变量值最后输入 %JAVA_HOME%\bin ...
- opacity--css + javascript兼容性代码
css设置opacity 之前看了别人写了一段关于opacity的css代码,没深入理解就copy过来自己用了一段时间,现在重新拿出来又深入研究了一下. .cla{ /* IE 8 */ -ms-fi ...
- NYOJ 722 数独
数独 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 数独是一种运用纸.笔进行演算的逻辑游戏.玩家需要根据9×9盘面上的已知数字,推理出所有剩余空格的数字,并满足每一 ...