http://acm.hdu.edu.cn/showproblem.php?pid=4951

2014多校 第八题 1008

2014 Multi-University Training Contest 8

Multiplication table

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

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

大意:给出一个p进制数的乘法表,第i行第j组(一组有两个数)表示i*j结果的高位和低位,例如样例中:

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
第二行的“2 3”表示0*0的结果为23,后面的“1 1”表示0*1的结果为11,依此类推。 这个乘法表不正确,是因为有熊孩子把数字打乱了,样例中,0被换成了1, 1被换成了3, 2被换成了2, 3被换成了0,第一行的0*0等于23其实是3*3=21(四进制)。
求各个数的映射。 题解:探寻乘法表的规律。
数字太大,不能暴搜,而且乘法表是有规律的,我们可以根据数字出现的种类数来判断数字。
样例中有一行全是1,我们可以想到1其实就是0,。
最后一行的高位全是1,我们根据10进制的乘法表来观察,什么时候高位会不变呢?只有0*x和1*x高位是不变的,2*x的时候高位就有0或者1了。所以这个高位全是1的行代表的数字是1。
然后探寻普遍的规律:高位出现了多少种数字,这一位就是多少。(0、1高位都只出现1位数字,需特殊判断两个低位是否相等,相等说明是0,不等是1) (这题有点碉,我是没想到这么好的判断方法,当时暴搜了起来,果然不得力) 代码(一秒多过,加了读入输出优化的话可以到三百多毫秒):
 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usint unsigned int
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout)
#define mp make_pair int a[][][];
int c[];
int d[];
int p; void farm() {
int i,j;
memset(c,-,sizeof(c)); for(i=; i<p; i++) {
memset(d,,sizeof(d));
int cnt=;
for(j=; j<p; j++)
if(d[ a[i][j][] ]==) {
d[ a[i][j][] ]=;
cnt++;
}
if(cnt==) cnt= a[i][][]==a[i][][]?:;
//b[i]=cnt;
c[cnt]=i;
} for(i=; i<p; i++) {
printf(" %d",c[i]);
}
puts("");
} int main() {
int cas=, ans;
int i,j;
while(scanf("%d",&p)!=EOF) {
if(p==)break;
for(i=; i<p; i++) {
for(j=; j<p; j++) {
//scanf("%d%d",&a[i][j][1],&a[i][j][0]);
scanf("%d%d",&a[i][j][],&a[i][j][]);
}
}
printf("Case #%d:",cas++);
farm();
}
return ;
}
 

hdu4951 Multiplication table (乘法表的奥秘)的更多相关文章

  1. [LeetCode] Kth Smallest Number in Multiplication Table 乘法表中的第K小的数字

    Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number ...

  2. [Swift]LeetCode668. 乘法表中第k小的数 | Kth Smallest Number in Multiplication Table

    Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number ...

  3. 九九乘法表,全js编写,放入table表格带入页面渲染出来

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 【Kata Daily 190911】Multiplication Tables(乘法表)

    题目: Create a function that accepts dimensions, of Rows x Columns, as parameters in order to create a ...

  5. Codeforces Codeforces Round #319 (Div. 2) A. Multiplication Table 水题

    A. Multiplication Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/57 ...

  6. Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)

    转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...

  7. Codeforces Round #256 (Div. 2) D. Multiplication Table 二分法

     D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input st ...

  8. Codeforces Round #256 (Div. 2) D. Multiplication Table 很有想法的一个二分

    D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input stand ...

  9. 记得初学JS时候练个九九乘法表都写的要死要活

    还记得当初刚接触JS时候,看到视频中老师写了个九九乘法表,觉得好神奇,可是自己在下面动手写了半天还是有各种问题,甚是懊恼啊.今又看到园子里有关于乘法表的博文,出于对过去的不舍与缅怀,遂重写一遍. &l ...

随机推荐

  1. 【vijos1900】 学姐吃寿司

    https://vijos.org/p/1900 (题目链接) 题意 给出一个01环,问最少经过多少次相邻互换使得所有的0聚在一坨,所有的1聚在一坨. Solution 源自:LCF Solution ...

  2. 【bzoj1178】 Apio2009—CONVENTION会议中心

    http://www.lydsy.com/JudgeOnline/problem.php?id=1178 (题目链接) 题意 给出n个区间,问在区间两两不相交的情况下最多能选出多少区间,并输出字典序最 ...

  3. 【bzoj1951】 Sdoi2010—古代猪文

    http://www.lydsy.com/JudgeOnline/problem.php?id=1951 (题目链接) 题意 废话一堆..求解: Solution 真的是数论经典题,什么都用上了. 因 ...

  4. MVC重写DefaultModelBinder实现自定义模型绑定

    在编写前台页面的时候为了使url传递参数的简短,比如personId="1"  我们通过url传递成pid=1  那么在后台action方法接受的模型Person类 的属性为per ...

  5. sstream使用简介

    sstream即字符串流.sstream有三种类:ostringstream:用于输出操作,istringstream:用于输入操作,stringstream:用于输入输出操作其实我感觉只用第三个就够 ...

  6. Dword、LPSTR、LPWSTR、LPCSTR、LPCWSTR、LPTSTR、LPCTSTR

    DWORD:本来被定义为unsigned long,DWORD的含义就是双字,一个字是2字节,双字就是32字节. 但是在C/C++中,经常会用到把一个指针转换成数字储存,然后再将其传唤为指针调用.那么 ...

  7. javascript表单验证

    表单HTML <form action="" method="post"> <fieldset class="login" ...

  8. HTML5学习总结-03 地理定位

    一 地理定位 HTML5 Geolocation(地理定位)用于定位用户的位置. 1 地理定位 地理位置 经度  :   南北极的连接线 纬度  :   东西连接的线 位置信息从何而来: IP地址 G ...

  9. 捉襟见肘之message sent to deallocated instance 0x16f62a70

    出现的问题(真机ios8到ios9测试没有问题,真机ios7.1出现问题): -- :::60b] *** -[ChatViewController scrollViewDidScroll:]: me ...

  10. NOIp模拟赛 旅游

    很神奇的一道题,金策大爷给的题解: 什么叫神犇什么叫蒟蒻? IOI冠军的一句基本相同让我思考了一下午. 看完了题解我就想都没想开始用遍历二分图搞,但是搞到了65分后就总是会WA掉7组. 然后仔细的看了 ...