链接: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。所以稍有迷茫),分别代表了新的不同的数。乘法表上的数也都被映射了。如今要找出映射到了什么新的数。

思路:毫无疑问。出现最多的数一定原来是0,而(p-1)*(p-1) = p^2-2*p+1 = p*(p-2)+1,而且仅仅有(p-1)*(p-1)时,”十位“会出现p-2。其它相乘的”十位“数字最大也仅仅是p-3,所以相应着行列都是p-1的数的位置,”十位“代表的一定是p-2,然后递推着找(p-1)*(p-2)的"十位"是N-3,向下找就能找到全部数字的映射了。

(2进制须要特判,由于p-2=0)

代码:(C++过的)

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-10
#define INF 0x7fffffff
#define maxn 10005
#define PI acos(-1.0)
#define seed 31//131,1313
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int a[505][1005];
int tt[505][2];
int main()
{
int T,t=0;
int M[505];
while(scanf("%d",&T))
{
t++;
if(T==0)
break;
memset(M,-1,sizeof(M));
memset(tt,0,sizeof(tt));
for(int i=0; i<T; i++)
for(int j=0; j<T; j++)
{
scanf("%d%d",&a[i][j*2+1],&a[i][j*2+2]);
tt[a[i][j*2+1]][0]++;
tt[a[i][j*2+2]][1]++;
}
printf("Case #%d:",t);
if(T==2)
{
if(tt[0][0]>tt[1][0])
printf(" 0 1\n");
else printf(" 1 0\n");
continue;
}
int all=0,pos=0;
for(int i=0; i<T; i++)
{
if(tt[i][0]+tt[i][1]>all)
{
all=tt[i][0]+tt[i][1];
pos=i;
}
}
M[0]=pos;
for(int i=0;i<T;i++)
{
if(tt[i][0]==1)
{
M[T-2]=i;
break;
}
}
for(int i=0;i<T;i++)
if(a[i][i*2+1]==M[T-2])
{
M[T-1]=i;
break;
}
for(int i=2;i<=T-1;i++)
M[T-i-1]=a[M[T-1]][2*M[T-i]+1];
for(int i=0;i<T;i++)
printf(" %d",M[i]);
printf("\n");
}
return 0;
}

HDU 4951 Multiplication table 阅读题的更多相关文章

  1. 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). 根 ...

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

  3. UVALive 7511 L - Multiplication Table 数学模拟题,暴力

    给定一副表,问其是否合法. 思路:当全部是?的时候,是合法的. 如果不是,那么,就找到一个数字,把它拆成若干个a*b的形式,去判断其它点是否合法即可. 拆分数字的时候,只需要枚举到sqrt(n),因为 ...

  4. hdu4951 Multiplication table (乘法表的奥秘)

    http://acm.hdu.edu.cn/showproblem.php?pid=4951 2014多校 第八题 1008 2014 Multi-University Training Contes ...

  5. cf448D Multiplication Table

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

  6. Codeforces 448 D. Multiplication Table 二分

    题目链接:D. Multiplication Table 题意: 给出N×M的乘法矩阵要你求在这个惩罚矩阵中第k个小的元素(1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m). 题解: n ...

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

  8. hdu 4951

    Multiplication table Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  9. LeetCode hard 668. Kth Smallest Number in Multiplication Table(二分答案,一次过了,好开心,哈哈哈哈)

    题目:https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/description/ 668. Kth S ...

随机推荐

  1. UVA 10313(完全背包变形)

    Problem B Pay the Price Input: standard input Output: standard output Time Limit: 2 seconds Memory L ...

  2. SQL查询语句联系

    建立四个表,分别是学生表,课程表,成绩表和教师信息表 插入信息: 题目: 1. 查询Student表中的所有记录的Sname.Ssex和Class列 select Sname,Ssex,Class f ...

  3. WM_CLOSE、WM_DESTROY、WM_QUIT学习总结(点击关闭按钮会触发WM_CLOSE消息,DestroyWindow API会触发WM_DESTROY和WM_NCDESTROY消息,MSDN上写的很清楚)

    WM_CLOSE:关闭应用程序窗口 WM_DESTROY:关闭应用程序 WM_QUIT:关闭消息循环 只有关闭了消息循环,应用程序的进程才真正退出(在任务管理器里消失). win32应用程序的完整退出 ...

  4. java学习笔记08--泛型

    java学习笔记08--泛型 泛型可以解决数据类型的安全性问题,它主要的原理,是在类声明的时候通过一个标识标识类中某个属性的类型或者是某个方法的返回值及参数类型.这样在类声明或实例化的时候只要指定好需 ...

  5. ubuntu12.04下搭建ftpserver

    楼主想把同学硬盘里面的200多G电影共享给实验室的小伙伴们看,就打算在内网server上搭建一个ftp的server. 1.安装ftp 首先在终端下键入例如以下内容,安装ftpserver: sudo ...

  6. 【机器学习】SVM核函数

    知识预备 1. 回顾:logistic回归出发,引出了SVM,即支持向量机[续]. 2.  Mercer定理:如果函数K是上的映射(也就是从两个n维向量映射到实数域).那么如果K是一个有效核函数(也称 ...

  7. 探索Oracle之数据库升级七 11gR2 to 12c 升级完毕后插入PDB

    探索Oracle之数据库升级七 11gR2 to 12c 升级完毕后插入PDB 前言:        从Oracle 12c開始,引入了容器数据库的概念,能够实现数据库插拔操作,例如以下图: 如今我们 ...

  8. 找工作笔试面试那些事儿(8)---常问的CC++基础题

    这一部分是C/C++程序员在面试的时候会被问到的一些题目的汇总.来源于基本笔试面试书籍,可能有一部分题比较老,但是这也算是基础中的基础,就归纳归纳放上来了.大牛们看到一笑而过就好,普通人看看要是能补上 ...

  9. TreeSet排序

    TreeSet的排序能够通过两种方法来实现: 1.通过TreeSet(Comparator<? super E> comparator) 构造方法指定TreeSet的比較器进行排序. 2. ...

  10. TypeError: Cannot read property &#39;style&#39; of null 错误解决

    错误信息例如以下: JSP代码例如以下: <c:if test ="${not empty excelErrors}"> <div id="excelE ...