天天看點

【NOIP2016提高組 day1】玩具謎題【NOIP2016提高組 day1】玩具謎題

【NOIP2016提高組 day1】玩具謎題

【NOIP2016提高組 day1】玩具謎題【NOIP2016提高組 day1】玩具謎題
【NOIP2016提高組 day1】玩具謎題【NOIP2016提高組 day1】玩具謎題
【NOIP2016提高組 day1】玩具謎題【NOIP2016提高組 day1】玩具謎題

題解:

這是一道模拟題,不過呢大家可以取一下巧的如果目前發現與目标的方向一緻就繼續,否則就反向

#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int n,m,flag,ans,bs,fx;
struct oo{
   int fx;
   string name;
}peo[100010];
string name;
ll read(){
   ll num=0,f=1;
   char ch=getchar();
   while(ch>'9'||ch<'0'){
   	if(ch=='-') f=-1;
   	ch=getchar();
   }
   while(ch>='0'&&ch<='9'){
   	num=(num<<3)+(num<<1)+ch-'0';
   	ch=getchar();
   }
   return num;
}
int main(){
   n=read();
   m=read();
   for(int i=1;i<=n;i++){
   	fx=read();
   	cin>>name;
   	peo[i].name=name;
   	peo[i].fx=fx;
   }
   ans=1;
   for(int i=1;i<=m;i++){
   	fx=read();
   	bs=read();
   	if(abs(peo[ans].fx-fx))
   		ans+=bs;
   	else ans-=bs;
   	while(ans<=0) ans+=n;
   	while(ans>n) ans-=n;
   }
   cout<<peo[ans].name;
   return 0;
}
           

繼續閱讀