[Luogu]P1563 玩具谜题

learningman 2月 06, 2018

集训第一天,水题

然而我还是切不出来(逃

洛谷链接

#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>#define maxn 100001int fx[maxn];int location=0;using namespace std;int main() { string name[maxn]; int n,m; scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) { cin>>fx[i]>>name[i]; } for(int j=1;j<=m;j++) { int a=0,s=1; cin>>a>>s; if(a==0&&fx[location]==0) location-=s; if(a==1&&fx[location]==0) location+=s; if(a==1&&fx[location]==1) location+=s; if(a==0&&fx[location]==1) location-=s; } while(location<0) { location=(n-1-(location%n))%n; } cout<<name[location]; return 0; }

4个月过去了...我终于想起这里还有一道没A的题....

#include <bits/stdc++.h>struct people{ bool dir; char name[20];}child[100001];int loc=1;int main(){ int n,m; scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) { //printf("read %d time\n",i); scanf("%d",&child[i].dir); scanf("%s",&child[i].name); } for(int i=1;i<=m;i++) { //printf("run %d time\n",i); int dir_define; int countnum; scanf("%d",&dir_define); scanf("%d",&countnum); if(dir_define&&child[loc].dir) { loc-=countnum; //printf("choose1 \n"); } else if(!dir_define&&child[loc].dir) { loc+=countnum; //printf("choose2 \n"); } else if(dir_define&&!child[loc].dir) { loc+=countnum; //printf("choose3 \n"); } else { loc-=countnum; //printf("choose4 \n"); } //printf("locbefore=%d \n",loc); if(loc>n) { loc%=n; } if(loc<=0) { loc+=n; } //printf("now is %d times,and the person is %s\n",i,child[loc].name); //printf("locafter=%d \n",loc); } printf("%s",child[loc].name); return 0;}

本文采用 CC BY-NC-SA 3.0 协议进行许可,在您遵循此协议的情况下,可以自由共享与演绎本文章。
本文链接:https://learningman.top/archives/25.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注




you're currently offline