34 条题解
-
20
qwe1294410750 LV 4 @ 8 年前
完美AC/
-
16 年前@
nb
-
17 年前@
关键都在一句话里了.对于某个询问来讲,它模拟的方向和左右的方向以及小人脸部的朝向有关系.可以用异或运算判断模拟的方向,如果异或结果是1就逆时针,否则顺时针.
-
05 年前@
-
05 年前@
分析:
1.仔细看题目,找到有用信息;
2.本题分量种情况:一个是小人面向内,另一个是向外;
3.然后根据两种情况选择是向左还是向右;
4.然后再分析一下加减的情况;
不太会写题解,大家原谅。。。
下面上代码O(n):
#include<bits/stdc++.h>
using namespace std;
int n,m,w=1;
struct node{
int p,q;
string z;
}g[100010]; //定义结构体
node h[100010];
int main(){
cin>>n>>m; //输入
for(int i=1;i<=n;i++) cin>>g[i].p>>g[i].z; //循环输入
for(int i=1;i<=m;i++) cin>>h[i].p>>h[i].q;
for(int i=1;i<=m;i++){
if(g[w].p==0){
if(h[i].p==0) w-=h[i].q;
else w+=h[i].q;
} //小人面向内
else{
if(h[i].p==0) w+=h[i].q;
else w-=h[i].q;
} //小人面向外
if(w<=0) w+=n; //进行加减
if(w>n) w-=n;
}
cout<<g[w].z<<endl;
return 0;
} -
06 年前@
#include<iostream>
#include<string>
using namespace std;
int ans=1,n,m;
bool cx[100010],rl[100010];
string s[100010];
int gs[100010];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>cx[i]>>s[i];
}
for(int i=1;i<=m;i++)
{
cin>>rl[i]>>gs[i];
}
for(int i=1;i<=m;i++)//cx 0表示朝向圈内,1表示朝向圈外//rl 0表示向左数,1表示向右数
{
if((cx[ans]==0&&rl[i]==1)||(cx[ans]==1&&rl[i]==0))
{
if(ans+gs[i]>n)
{
(ans+=gs[i])-=n;
}
else ans+=gs[i];
}
else
{
if(ans-gs[i]<=0)
{
(ans-=gs[i])+=n;
}
else ans-=gs[i];
}
}
cout<<s[ans]<<endl;
return 0;
} -
07 年前@
-
07 年前@
var m,n,i,j,k,l:longint;
s:char;
a,b,c:array[0..10100] of longint;
st:array[0..10100] of string;
beginreadln(m,n);
for i:=1 to m do
readln(a[i],s,st[i]);
for i:=1 to n do
readln(b[i],c[i]);
l:=1;
k:=0;
for i:=1 to n do
begin
if a[l]=0 then if b[i]=0 then l:=l-c[i]
else l:=l+c[i]
else if b[i]=0 then l:=l+c[i]
else l:=l-c[i];
if l>m then l:=l-m;
if l<1 then l:=l+m;
end;
writeln(st[l]);end.
-
07 年前@
-
07 年前@
简洁
#include<iostream>
using namespace std;
int main(){int n,m;
cin>>n>>m;
int a[m],s[m],count = 1;
struct man{
string name;
int dir;
}total[n+1];
for(int i= 1;i<=n;i++){
cin>>total[i].dir>>total[i].name;
}
for(int i = 0;i<m;i++){
cin>>a[i]>>s[i];
if(a[i] == total[count].dir){count = (count-s[i])%n; if(count<=0)count+=n;}
else {count = (count+s[i])%n;if(count==0)count+=n;}
}
cout<<total[count].name;
} -
07 年前@
#include<iostream>
#include<algorithm>
using namespace std;
struct p
{
string name;
int turn;
}a[100001];
int main()
{
int n,m,x[100001],y[100001];
int t=1;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i].turn>>a[i].name;
for(int i=1;i<=m;i++)
{
cin>>x[i]>>y[i];
if(a[t].turn!=x[i])
{
t+=y[i];
while(t>n)t=t-n;
}
else
{
t-=y[i];
while(t<=0)t=t+n;
}
}
cout<<a[t].name;
return 0;
} -
07 年前@
#include<iostream>
#include<algorithm>
using namespace std;
struct p
{
string name;
int turn;
}a[100001];
int main()
{
int n,m,x[100001],y[100001];
int t=1;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i].turn>>a[i].name;
for(int i=1;i<=m;i++)
{
cin>>x[i]>>y[i];
if(a[t].turn!=x[i])
{
t+=y[i];
while(t>n)t=t-n;
}
else
{
t-=y[i];
while(t<=0)t=t+n;
}
}
cout<<a[t].name;
return 0;
} -
07 年前@
#include<iostream>
#include<algorithm>
using namespace std;
struct p{
string name;
int turn;
}a[21];
int main()
{
int n,m,x[1001],y[1001];
int t=1;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i].turn>>a[i].name;
for(int i=1;i<=m;i++)
{
cin>>x[i]>>y[i];
if(a[t].turn!=x[i])
{
t+=y[i];
while(t>n)
{
t=t-n;
}
}
else
{
t-=y[i];
while(t<0)
{
t=t+n;
}
}
}
cout<<a[t].name;
return 0;
} -
07 年前@
148ms通过 写了
ReadInt
,ReadBool
和ReadStr
优化读入速度,并且做了循环展开qwq -
07 年前@
//脑子清晰 数组别小就没问题
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int a[100001],b[100001],c[100001];
char job[100001][11];
int main()
{ int n,m,i,j,temp=1;
cin>>n>>m;
for(i=1;i<=n;i++)
cin>>a[i]>>job[i];
for(i=1;i<=m;i++)
cin>>b[i]>>c[i];
for(i=1;i<=m;i++)
{
if(a[temp]==0)
if(b[i]==0)
{
temp=temp-c[i];
if(temp<=0)temp+=n;
}
else
{
temp=temp+c[i];
if(temp>n)temp-=n;
}
else
if(b[i]==0)
{
temp=temp+c[i];
if(temp>n)temp-=n;
}
else
{
temp=temp-c[i];
if(temp<=0)temp+=n;
}
}
cout<<job[temp]<<endl;
//system("pause");
return 0;
} -
07 年前@
简单模拟
不弄乱了就可以 ^(* ̄(oo) ̄)^
这是accepted的code:之前写的过了18个(except NO.12 & NO.16)
有人能帮我找一下错在哪儿吗?谢谢!
-
07 年前@
#include<iostream>
#include<string>
#include<vector>
using namespace std;
struct people
{
string job;
bool facein;
};
vector<people> peos;
int gl(int s, int n, int t) {if (n-s < 0)
return t - (s - n);
else
return n - s;
}
int gn(int s, int n, int t) {if (s + n >= t)
return s+n-t;
else
return n + s;
}
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
people peo;
cin >> peo.facein >> peo.job;
if (peo.facein)
peo.facein = false;
else
peo.facein = true;
peos.push_back(peo);
}
int nowpeo = 0;
for (int j = 0; j < m; j++) {
int a, s;
cin >> a >> s;
bool t = peos[nowpeo].facein;
if (a == 0 && t == true) {
nowpeo = gl(s, nowpeo, n);
}
else if (a == 1 && t == false) {
nowpeo = gl(s, nowpeo, n);
}
else {
nowpeo = gn(s, nowpeo, n);
}
}
cout << peos[nowpeo].job;
} -
07 年前@
-
07 年前@
-
08 年前@
exciting,在vijos发的第一个题解233,水一下就好。
模拟就好了
对于逆时针输入,把它当成顺时针的,后面的左右对调即可。
移动时可能会产生负数或越界的,处理方式为 x=(n+x)与x%=n;
x<0时,意味着当前位置在n向前数x绝对值个单位的位置,x>=n由于是个环形的,很显然是x%n。
大概就是这样,稍微调试即可。环境:
win10 64bit
g++
gdb
atom(vim plugin)
信息
- ID
- 2003
- 难度
- 6
- 分类
- (无)
- 标签
- 递交数
- 2718
- 已通过
- 794
- 通过率
- 29%
- 被复制
- 10
- 上传者