2017 ICPC/ACM 沈阳区域赛HDU6223
Infinite Fraction Path
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1262 Accepted Submission(s): 224
The kingdom has N cities numbered from 0 to N - 1 and you are given an array D[0 ... N - 1] of decimal digits (0 ≤ D[i] ≤ 9, D[i] is an integer). The destination of the only one-way road start from the i-th city is the city labelled (i2 + 1)%N.
A path beginning from the i-th city would pass through the cities u1,u2,u3, and so on consecutively. The path constructs a real number A[i], called the relevant fraction such that the integer part of it is equal to zero and its fractional part is an infinite decimal fraction with digits D[i], D[u1], D[u2], and so on.
The best infinite fraction path is the one with the largest relevant fraction
For each test case, the first line contains the integer N (1 ≤ N ≤ 150000). The second line contains an array ofdigits D, given without spaces.
The summation of N is smaller than 2000000.
bfs + 剪枝
剪枝:
- 值小于当前层最大值的点移出队列
- 同一层在相同位置的移出队列
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= +;
const int maxm= 1e4+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
ll ne[maxn]; //ne[i]为以i为起点的边的终点
int v[maxn],ans[maxn],vis[maxn]; //权值、答案、i上一次在ans数组中出现的位置
char s[maxn];
int n,t;
struct node
{
int v,pos,ans; //表示当前节点的权值,下标i,在答案数组中的位置下标
node(){}
node(int v,int pos,int ans):v(v),pos(pos),ans(ans){}
};
struct compare
{
bool operator()(const node &a,const node &b) const //ans最小值优先 权值最大值优先
{
if(a.ans!=b.ans) return a.ans>b.ans;
else if(a.v!=b.v) return a.v<b.v;
return a.pos>b.pos;
}
};
priority_queue<node,vector<node>,compare> q;
int main()
{
scanf("%d",&t);
int kase=;
while(t--)
{
scanf("%d",&n);
scanf("%s",s);
memset(vis,-,sizeof(vis)); //初始化
memset(ans,-,sizeof(ans));
int ma=;
for(int i=;i<n;i++) //权值转化为整数 求出最大值 i的终点(i^2+1)%n
{
v[i]=s[i]-'';
ma=max(ma,v[i]);
ne[i]=(((ll)i*(ll)i+)%(ll)n);
}
// for(int i=0;i<n;i++)
// {
// printf("%d %d %d\n",i,v[i],next[i]);
// }
// printf("%d\n",ma);
for(int i=;i<n;i++)
{
if(v[i]==ma)
q.push(node(ma,i,)); //最大值先压入队列
}
while(!q.empty())
{
node t=q.top();q.pop();
if(ans[t.ans]==-) ans[t.ans]=t.v; //该位置初步确定一个值
if(ans[t.ans]>t.v) continue; //该节点的权值比以前小 直接跳过
if(vis[t.pos]<t.ans) vis[t.pos]=t.ans; //更新节点的 访问位置
else continue;
if(t.ans==n-) continue;
q.push(node(v[ne[t.pos]],ne[t.pos],t.ans+)); //加入新节点
}
printf("Case #%d: ",kase++);
for(int i=;i<n;i++)
printf("%d",ans[i]);
printf("\n");
}
return ;
}
2017 ICPC/ACM 沈阳区域赛HDU6223的更多相关文章
- 2017 ICPC/ACM 沈阳区域赛HDU6228
Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Subm ...
- 2015年ACM长春区域赛比赛感悟
距离长春区域赛结束已经4天了,是时候整理一下这次比赛的点点滴滴了. 也是在比赛前一周才得到通知要我参加长春区域赛,当时也是既兴奋又感到有很大的压力,毕竟我的第一场比赛就是区域赛水平,还是很有挑战性的. ...
- 2017沈阳区域赛Infinite Fraction Path(BFS + 剪枝)
Infinite Fraction Path Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java ...
- 2015沈阳区域赛Meeting(最短路 + 建图)
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- ICPC 2018 焦作区域赛
// 2019.10.7 练习赛 // 赛题来源:2018 ICPC 焦作区域赛 // CF链接:http://codeforces.com/gym/102028 A Xu Xiake in Hena ...
- hdu6223 Infinite Fraction Path 2017沈阳区域赛G题 bfs加剪枝(好题)
题目传送门 题目大意:给出n座城市,每个城市都有一个0到9的val,城市的编号是从0到n-1,从i位置出发,只能走到(i*i+1)%n这个位置,从任意起点开始,每走一步都会得到一个数字,走n-1步,会 ...
- 2017 ACM-ICPC 沈阳区域赛记录
出发日 中午坐大巴前往萧山机场. 哇开心又可以坐飞机了 飞机延误了.在候机大厅里十分无聊,先用机场的电脑玩了会小游戏 然后偷偷切了2个水题 (什么编译器IDE都没有,只能记事本了) 飞机上什么东西都没 ...
- hdu6229 Wandering Robots 2017沈阳区域赛M题 思维加map
题目传送门 题目大意: 给出一张n*n的图,机器人在一秒钟内任一格子上都可以有五种操作,上下左右或者停顿,(不能出边界,不能碰到障碍物).题目给出k个障碍物,但保证没有障碍物的地方是强联通的,问经过无 ...
- HDU 6229 Wandering Robots(2017 沈阳区域赛 M题,结论)
题目链接 HDU 6229 题意 在一个$N * N$的格子矩阵里,有一个机器人. 格子按照行和列标号,左上角的坐标为$(0, 0)$,右下角的坐标为$(N - 1, N - 1)$ 有一个机器人, ...
随机推荐
- boost::format(字符串格式化库)
这段时间学习boost库的使用,撰文一方面留以备用,另一方面就是shared精神. format主要是用来格式化std::string字符串以及配合std::cout代替C语言printf() 使用f ...
- linux下增加磁盘改变指定文件路径分区挂载点和迁移数据
Centos7 系统上原有目录/data 挂载根目录下,空间有点小,我们需要把/data目录挂载到另一个磁盘,同时把数据迁移. 1.查看分区情况 fdisk -l 2.查看路径对应分区情况 df -l ...
- P、NP、NP完全问题
如果一个算法的最差时间效率属于O(p(n)),则该算法可以在多项式的时间内对问题进行求解,其中p(n)是输入规模n的一个多项式函数. 可以在多项式时间内求解的问题是易解的.不能在多项式时间内求解的问题 ...
- URL加载页面的过程
总体过程: 1.DNS解析 2.TCP连接 3.发送HTTP请求 4.服务器处理请求并返回HTTP报文 5.浏览器解析渲染页面 6.连接结束 一.DNS解析 在互联网中,每一台机计算机的唯一 标识是他 ...
- thinkinginjava学习笔记10_容器
Java中并没有像Perl.Python.Ruby那样对容器有直接的支持,但是可以依靠容器类来完成相同的工作: 泛型 使用一个ArrayList对象可以保存一系列的对象,如: ArrayList ap ...
- 454ITS数据按barcode和primer分类程序v1.0
不知道有什么好办法可以让primer允许漏配,现在仅仅是允许错配,还是有一些没有配上,454数据有些primer漏配了一些,下一步解决这个问题 #include <cstdio> #inc ...
- 解决adb push时出现的"Read-only file system"问题
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- 通过window.location.search获取页面url传递的参数
function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...
- entity framework学习
资源 Entity Framework技术导游系列开篇与热身
- Transact-SQL参考--学习笔记
基本的就不累赘了. 运算符 除法: dividend / divisor 如果用一个整数的 divisor 去除整数的 dividend,其结果是一个整数,小数部分被截断,如果要有小数可以将divid ...