思路   如果进制为p    那么当x<p时 (p-1)*(p-x)=(p-(x+1))  *p +x     因为x<p  所以没有进位  所以高位上的数字为    p-(x+1)。

根据上面所述。 只要我们能找出 p-1   那么我们根据(p-1)*(p-1)的高位为p-2 就能找出p-2 。找出p-2根据  (p-1)*(p-2)的高位为(p-3) 就能找出p-3.。。。。任务就转化成找出p-1。 我们会发现 从0-(p-2)  都会出现在高位。唯有p-1不会出现。那么就知道要出高位没出现过的数字  就为p-1    那么问题就解决了。由于题目有说读入数据量很大,可以加个读入优化。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include <iostream>
using namespace std;
int ans[];
bool bo[];
int a[][];
inline int ReadInt()//优化接受int数,省时间,具体内容自己看懂,当成模板使用
{
char ch = getchar();
int data = ;
while (ch < '' || ch > '')
ch = getchar();
do
{
data = data * + ch - '';
ch = getchar();
} while (ch >= '' && ch <= '');
return data;
}
int s[][];
int main() {
int p,ri=;
while(scanf("%d",&p)&&p)
{
for(int i=;i<p;++i)bo[i]=false;
for(int i=;i<p;++i)
{
for(int j=;j<*p;++j)
{
a[i][j]=ReadInt();
if(!(j&))
{
s[i][j>>]=a[i][j];
bo[a[i][j]]=true;
}
}
}
for(int i=;i<p;++i)
if(!bo[i])
{
ans[p-]=i;
break;
}
int pre=ans[p-];
for(int i=p-;i>=;--i)
{
ans[i]=s[ans[p-]][pre];
pre=ans[i];
}
printf("Case #%d:",++ri);
for(int i=;i<p;++i)
printf(" %d",ans[i]);
puts("");
}
return ;
}

最新文章

  1. ORACLE查看数据文件包含哪些对象
  2. javascript this 详解
  3. 对于java中的变量问题
  4. HTML第二部分 CSS样式表
  5. find命令小结
  6. SQL Server数据库事务日志存储序列
  7. .Xresources 配置文件
  8. Spring框架(4)---AOP讲解铺垫
  9. PAT1116: Come on! Let&#39;s C
  10. Linux 链路聚合
  11. 在线排错之curl命令详解
  12. Flask源码阅读-第三篇(flask\_compat.py)
  13. http 协议三次握手
  14. jquery zTree异步搜索的例子--搜全部节点
  15. Webflux快速入门
  16. IBAction:IBOutlet:注意事项
  17. [转]Java中BigDecimal的使用
  18. 驱动程序多线程 PsCreateSystemThread
  19. Linux安装配置SVN服务器【转】
  20. [Erlang20]一起攻克Binary

热门文章

  1. Dream It Possible
  2. 浏览器请求URL原理
  3. Java-坦克大战
  4. 办公大楼3D指纹门禁系统解决方案
  5. solrconfig.xml解析
  6. Analyzer中进行货币转换
  7. centos7 加入自启动服务的方法 以jexus为例
  8. 相机位姿估计0:基本原理之如何解PNP问题
  9. 一、Hello World
  10. (转)Linux grep