当前位置:网站首页>2017 G icpc shenyang Infinite Fraction Path BFS + pruning

2017 G icpc shenyang Infinite Fraction Path BFS + pruning

2022-08-09 07:02:00 swust_fang

The meaning of the question: Given a string array of length n, you can select the starting point to jump n times, from point i can only jump to the position of (i*i+1)%n, and finally find a maximum lexicographical order.

Ideas: The largest number is required, that is, each step is the largest, so the largest number is entered into the team for bfs to jump to the next step.

Pruning: 1. If the point jumping to the next step is smaller than other points jumping to the next step, remove it

2. If there are two points that reach the same point through the same synchronization number, then their subsequent states are also the same, so they are also eliminated.

ok, it is all.

First we use a structure to wrap the number of steps and the position pos node{step,pos}

Use the nex array to represent the value of the number from the pos point to the next position

Then we customize a sorting function in the priority queue (the most important pruning is actually the sorting method)

If the value of step and the next step nex[pos] are equal, we sort by pos from small to large

If step is equal, nex[pos] is not equal, according to nex[pos] from big to small

If the steps are not equal, follow the steps from small to large

Pit!!!Pay attention to i*i burst int, disgusting

#include#include#include#include#include#include#include#include#include#include#include#include#define myself i,l,r#define lson i<<1#define rson i<<1|1#define Lson i<<1,l,mid#define Rson i<<1|1,mid+1,r#define half (l+r)/2#define inff 0x3f3f3f3f#define lowbit(x) x&(-x)#define PI 3.14159265358979323846#define min4(a, b, c, d) min(min(a,b),min(c,d))#define min3(x, y, z) min(min(x,y),min(y,z))#define pii make_pair#define pr pairconst int dir[4][2] = {0, -1, -1, 0, 0, 1, 1, 0};typedef long long ll;const ll inFF = 9223372036854775807;typedef unsigned long long ull;using namespace std;const int maxn=2e5+5;int d[maxn],ans[maxn],nex[maxn];char s[maxn];struct node{int pos,step;bool friend operator<(node ​​s,node e){if(s.step==e.step&&nex[s.pos]==nex[e.pos]) return s.pose.step;}};int main(){int t;// freopen("E://1.in","r",stdin);// freopen("E://1.out","w",stdout);cin>>t;for(int p=1;p<=t;p++){int n;ll h;cin>>n;scanf("%s",s);int maxs=0;for(int i=0;iq;for(int i=0;i

原网站

版权声明
本文为[swust_fang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208090700344552.html