HDU 4951 Multiplication table(找規律)
題目大意:給出一個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,依此類推。
Total Submission(s): 736 Accepted Submission(s): 335
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,依此類推。
寫出九九乘法表之後你會發現當i*j中,所有高位的數字為0-i-1。然後就可以雜湊統計出來高位有多少個,那這一行就是幾了啊。
Multiplication table
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 736 Accepted Submission(s): 335
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.
For example, the following is a multiplication table in base 4:
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:
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!
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.
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
Author
xudyh
Source
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define M 1000100
///#define LL __int64
#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x)
using namespace std;
const int maxn = 510;
int num[maxn];
int mp[maxn][maxn][2];
int vis[maxn];
int main()
{
int Case = 1;
int p;
while(~scanf("%d",&p) && p)
{
for(int i = 0; i < p; i++)
for(int j = 0; j < p; j++) scanf("%d %d",&mp[i][j][1], &mp[i][j][0]);
for(int i = 0; i < p; i++)
{
int cnt = 0;
memset(vis, 0, sizeof(vis));
for(int j = 0; j < p; j++)
{
if(!vis[mp[i][j][1]])
{
vis[mp[i][j][1]] = 1;
cnt++;
}
}
if(cnt == 1)
if(mp[i][0][0] == mp[i][1][0]) cnt = 0;
num[cnt] = i;
}
printf("Case #%d: ", Case++);
for(int i = 0; i < p-1; i++) printf("%d ",num[i]);
printf("%d\n",num[p-1]);
}
return 0;
}
相關文章
- HDU 6298 Maximum Multiple(找規律)
- A Multiplication Game (博弈,規律)GAM
- HDU5139 Formula (找規律+離線處理)ORM
- HDU 5795 A Simple Nim (SG函式+打表找規律)函式
- HDU-6415 Rikka with Nash Equilibrium (DP/找規律)UI
- HDU 5439 Aggregated Counting(找規律+預處理)
- 打表找規律
- HDU 2897-邂逅明下(博弈-SG函式打表找規律)函式
- HDU 1847 Good Luck in CET-4 Everybody!(找規律版巴什博奕)Go
- [6 kyu] Multiplication table
- HDU 1847-Good Luck in CET-4 Everybody!(博弈-SG函式/找規律)Go函式
- HDU4342 History repeat itself數學規律題
- HDU 4920 Matrix multiplication(矩陣相乘)矩陣
- Codeforces 448D Multiplication Table
- Touring cities (找規律 哈密爾頓迴路)
- 數學規律題,數論知識:hdu1792
- LeetCode-6. Z字形變換(找規律)LeetCode
- codeforces 340CTourist Problem(找規律數學題)
- HUNAN -11566 Graduation Examination(找規律)NaN
- Gym - 101532A Subarrays Beauty(位操作找規律)
- 【組合數+找規律】codeforces 815B - Karen and Test
- QOJ7789-一道位運算找規律好題
- codeforces448D Multiplication Table(二分答案)
- UVALive 7511 Multiplication Table (數學模擬題)
- HDU 1792 - A New Change Problem(規律,最大不能組合數及其個數)
- HDU 3682To Be an Dream Architect(統計規律題目 三線相交bug)
- HDU4920 Matrix multiplication (CPU cache對程式的影響)
- ZOJ Monthly, January 2019 - A Little Sub and Pascal's Triangle(找規律)
- EMS單號規律與順豐單號規律(C#)C#
- 「暑期訓練」「Brute Force」 Multiplication Table (CFR256D2D)
- 【LeetCode動態規劃#04】不同的二叉搜尋樹(找規律,有點像智力題)LeetCode動態規劃
- leedcode-單詞規律
- 圖片跨域規律探尋跨域
- LeetCode-單詞規律LeetCode
- 索引的應用規律總結索引
- Java欄位初始化規律Java
- Flink Table/SQL API 規劃 —— Dynamic TableSQLAPI
- 山東省第四屆ACM大學生程式設計競賽-Alice and Bob(二進位制&&找規律)ACM程式設計