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 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

可以抽象为10进制找到规律,输入输出数据太多,需要用到输入挂,否则会T

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <set>
#include <vector>
#include <algorithm>
#define maxn 510
using namespace std;

int mark[maxn];
void read(int &a) {
    int t;
    while (t = getchar(), isspace(t));
    a = t - '0';
    while (t = getchar(), !isspace(t)) a = a * 10 + t - '0';
}
int mk[maxn],cnt[maxn],get_zero[maxn];
int main()
{
	//freopen("1007.in","r",stdin);
	//freopen("data.out","w",stdout);
	int n;
	int cas=0;
	while (~scanf("%d",&n))
	{
		for(int i=0;i<n;i++)
		{
			cnt[i]=0;
		}
		if(n==0) break;
		int tp,tp2;

		printf("Case #%d:",++cas);
		for(int i=0;i<n;i++)
		{
			int bl=0;
			memset(mk,-1,sizeof(mk));
			for(int j=0;j<n;j++)
			{
				read(tp);read(tp2);
				//scanf("%d %d",&tp,&tp2);
				if(mk[tp]!=tp){
					cnt[i]++;
					mk[tp]=tp;
				}
				if(mk[tp2]!=tp2)
				{
					bl=1;
				}
			}
			if(!bl&&cnt[i]==1) {
				cnt[i]=0;
			}

		}
		for(int i=0;i<n;i++)
		{
	//		printf("%d\n",cnt[i]);
			mark[cnt[i]]=i;
		}
		for(int i=0;i<n;i++)
		{
			printf(" %d",mark[i]);
		}
		puts("");

	}
	return 0;
}

HDU 4951 Multiplication table 数论

时间: 2024-08-11 03:36:20

HDU 4951 Multiplication table 数论的相关文章

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 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 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

HDU 4861 Couple doubi(数论)

HDU 4861 Couple doubi 题目链接 题意:给定k,p,有k个球,每个球的值为1^i+2^i+...+(p-1)^i (mod p) (1 <= i <= k),现在两人轮流取球,最后球的值总和大的人赢,问先手是否能赢 思路:先手不可能输,非赢即平,那么只要考虑每种球的值, 利用费马小定理或欧拉定理,很容易得到该函数的循环节为p - 1, 那么i如果为p - 1的倍数,即为循环节的位置,那么每个值都为1,总和为p - 1 如果i不在循环节的位置,任取一个原根g,根据原根的性质,

HDU 3049 Data Processing 数论题解

Problem Description Chinachen is a football fanatic, and his favorite football club is Juventus fc. In order to buy a ticket of Juv, he finds a part-time job in Professor Qu's lab. And now, Chinachen have received an arduous task--Data Processing. Th

HDOJ 4915 Multiplication table

可以特判出0和1,再统计每行出现了多少种十位上的数就可以了.... 没有考虑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 Description Teacher Mai has

HDU4951: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

Codeforces Round #256 (Div. 2) D. Multiplication Table(二分查找)

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://codeforces.com/contest/448/problem/D -----------------------------------------------------------------------------------------------------------------------------------------------

Multiplication Table Example

Let's write a simple application that prompts the user for an integer, multiplies it by ascendingpowers of 2 (from 21 to 210) using bit shifting, and redisplays each product with leading paddedspaces. We will use C++ for the input-output. The assembl