60 分求助

P1563 [NOIP2016 提高组] 玩具谜题

@[张语诚ZYC](/user/314280) ```cpp #include<bits/stdc++.h> using namespace std; inline int read_int(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-'){ w=-1; } ch=getchar(); } while(ch>='0'&&ch<='9'){ s=10*s+ch-'0'; ch=getchar(); } return s*w; } const int MAXN=1e5+10; string job[MAXN]; int chaoxiang[MAXN]; int main(){ int n=read_int(); int m=read_int(); for(int i=1;i<=n;i+=1){ chaoxiang[i]=read_int(); cin>>job[i]; } int cur=1; for(int i=1;i<=m;i+=1){ int a=read_int(); int s=read_int(); if(chaoxiang[cur]==a){ s=-s; } cur+=s; while(cur>n){ cur-=n; } while(cur<1){ cur+=n; } // cur=((cur-1+s+n)%n)+1; } cout<<job[cur]; return 0; } ```
by yizhiming @ 2022-12-11 21:19:59


修改 cur 和判断朝向的地方写错了
by yizhiming @ 2022-12-11 21:21:43


@[yizhiming](/user/369399) 谢谢dalao
by 张语诚ZYC @ 2022-12-11 21:22:29


@[张语诚ZYC](/user/314280) 你已经落魄到这样了吗( 当年您还是吊打我的说
by yizhiming @ 2022-12-11 21:23:28


@[yizhiming](/user/369399) 不是您吊打我吗,关于一年没学从头补这件事
by 张语诚ZYC @ 2022-12-11 21:30:27


```cpp #include <iostream> #include <string> using namespace std; const int MAXN = 1e6 + 5; struct node { int head; string name; }a[MAXN]; int n, m, x, y; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i].head >> a[i].name; } int now = 0; for (int i = 1; i <= m; i++) { cin >> x >> y; if ((a[now].head ^ x) == 0) { now = (now + n - y) % n; } else if ((a[now].head ^ x) == 1) { now = (now + y) % n; } } cout << a[now].name << endl; return 0; } ```
by int_stl @ 2022-12-21 17:35:16


|