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)$ 有一个机器人, ...
随机推荐
- Mac中Eclipse安装和使用svn
Eclipse版本为Neon Release (4.6.0) 安装svn 安装HomeBrew 在终端中输入 ruby -e "$(curl -fsSL https://raw.github ...
- 【ASP.NET系列】详解Views
描述 本片文章内容属于ASP.NET MVC系列视图篇,主要讲解View,大致内容如下: 1.Views文件夹讲解 2.View种类 3.Razor语法 4.对视图的基本操作 一 Views文件夹 ...
- Unix 文件系统读写时权限校验
文件系统中的所有文件都是在读出或写入时进行权限校验 一个问题,如果一个用户对一个普通文件有读写权限,在使用vim编辑时,管理员撤销掉此用户对此文件的写入权限 那么,这个普通用户还可以将修改写入文件吗?
- Cleaner, more elegant, and harder to recognize(翻译)
Cleaner, more elegant, and harder to recognize 更整洁,更优雅,但更难识别 看来,有些人把我几个月前一篇文章的标题"Cleaner,more e ...
- Python 项目实践三(Web应用程序)第五篇
接着上节继续学习,在这一节,我们将建立一个用户注册和身份验证系统,让用户能够注册账户,进而登录和注销.我们将创建一个新的应用程序,其中包含与处理用户账户相关的所有功能.我们还将对模型Topic稍做修改 ...
- egrep及扩展正则表达式 与正则表达式不同处
egrep及扩展正则表达式与正则表达式不同处 正则表达式有两类,分为基本正则表达式和扩展正则表达式,是使用命令egrep来使用扩展正则表达式,它与grep很多功能相同,仅在元字符上实现了些扩展扩展,在 ...
- 小子给大家分享一个或者多个新手创建tableview经常会遇到的坑(动态创建控件,xib的重用)
小子最近做了一个根据接口返回的数据在Cell中动态创建控件,感觉应该会一部分人卡在这里,小子就跟大家分享一下: 1.控件重复创建:这个问题出现的原因是动态创建的cell内容的时候,无法进行重用设置,所 ...
- 【转】Jenkins 安装与配置
基本配置: 1.Linux安装配置jdk环境 1.1.上传到 Linux 服务器:例如: 上传至: cd /usr/local 1.2.解压: rpm -ivh jdk-8u111-linux-x64 ...
- MySQL 5.7 InnoDB缓冲池NUMA功能支持——但是别高兴的太早
当前CPU都已是NUMA架构,相信除了历史遗留系统,很少会有数据库跑在SMP的CPU上了.NUMA架构带来的优势无言而语,CPU更快的内存访问速度,但是带来的问题也不言而喻,特别是对于数据库的影响.M ...
- H5开发中的故障
本篇博文会不断的收录我在做H5页面时遇到的问题以及解决方案,当然有的问题,我也没有遇到好的解决方案,所以如果你有解决的办法,请务必不吝赐教! H5开发中的故障 微信APP返回按钮不刷新页面 ...