197 条题解
-
5xuzhenyu LV 8 @ 2017-10-12 23:48:09
//用a数组表示当前位置果子的原来编号 //直接下压 模拟 ORZ。。。。 #include <iostream> using namespace std; int n,m; int a[11000]; int main() { cin>>n>>m; for(int i=1;i<=n;++i) a[i]=i; int top=n,now=1,l=1; while(true) { int x=(l*l*l)%5+1; now+=x; if(now>top){ now=1; now+=x; } if(l==m){ cout<<a[now]<<endl; break; } for(int i=now+1;i<=top;++i) a[i-1]=a[i]; top--; l++; } }
-
12021-08-30 15:57:59@
极致压行,码风起飞。
#include <bits/stdc++.h> using namespace std; int main() { int n,m,high=1,mark[10010]; cin>>n>>m; for(int i=1; i<=n; i++) mark[i]=i; for(int i=1; i<=m; i++){ int jump=(i*i*i)%5+1; high+=jump; if(high>n-i+1) high=jump+1; if(i!=m) for(int j=high+1; j<=n-i+1; j++) mark[j-1]=mark[j]; } cout<<mark[high]; return 0; }
-
12019-07-30 20:09:39@
C++
#include <iostream> using namespace std; int main() { int m,n,a[200],i,j,x,w=1; cin>>n>>m; for(i=0;i<n;i++) a[i]=i+1; for(i=1;i<=m;i++) { w+=i*i*i%5+1;if(w>n) {w=1;w+=i*i*i%5+1;} x=a[w-1]; for(j=w-1;j<n;j++) a[j]=a[j+1]; n--; } cout<<x; return 0; }
-
12018-07-30 11:47:17@
用了链表
```cpp
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for (int i=1;i<=n;i++)
#define REP(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define pos(x,y) (x+(y)*n)
const int N=100000+10;
const int inf=0x3f3f3f3f;
const ll mod=7777777;
const double eps=1e-8;int n,m;
struct node {
int v;
int pre,nxt;
} a[250];
int main() {
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
cin>>n>>m;
FOR(i,n) {
a[i].v=i;
a[i].pre=i-1,a[i].nxt=i+1;
}
a[n].nxt=0;
int now=1;
FOR(i,m) {
int t=i*i*i%5+1;
bool again=0;
FOR(j,t) {
now=a[now].nxt;
if (now==0) {
again=1;
break;
}
}
if (again) {
now=1;
FOR(j,t) now=a[now].nxt;
}
if (a[now].nxt) {
a[a[now].nxt].pre=a[now].pre;
}
if (a[now].pre) {
a[a[now].pre].nxt=a[now].nxt;
}
if (i==m) {
cout<<a[now].v<<endl;
}
now=a[now].nxt;
if (now==0) now=1;
}
return 0;
}
``` -
02020-07-30 18:35:21@
这道题很简单,采用模拟法
```cpp
#include "stdio.h"
int a[205];
int main() {
int N, m, i = 1, x = 0, j;
scanf("%d%d", &N, &m);
for(j = 1; j <= N; j++) a[j] = j; //赋值编号
while(1) {
int k = ((i*i*i)%5)+1;
x += k; //正常情况
if(x >= N) x = 1+k; //超过范围
if(i == m) { printf("%d", a[x]); break; } //到达目的,输出
for(j = x+1; j <= N; j++) a[j] = a[j+1]; //吃掉果子,删除该果子
i++, N--;
}
return 0;
} -
02017-05-07 22:38:23@
/* STL直接模拟即可,但是要注意呀 vector和数组一样开始元素是0,而第一个编号是1 一定要小心,总体还是挺简单的 Powder */ #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <vector> using namespace std; vector<int> v; int k=1; int n,m,ans; int main() { cin>>n>>m; v.clear(); for(int i=1;i<=n;i++) v.push_back(i); for(int i=1;i<=m;i++) { int p=i*i*i%5+1; k+=p; if(k>v.size()) k=p+1; if(i!=m)//第m次是跳到的位置,不能删除,需要判断 v.erase(v.begin()+k-1);//删除该位置 } cout<<v[k-1]<<endl;//k应该-1 return 0; }
-
02016-11-17 10:46:21@
water problem
pascal代码:
pascal
var
n,m,now,i,j:longint;
pd:array[1..500] of boolean;
begin
readln(n);
readln(m);
fillchar(pd,sizeof(pd),true);
now:=1;
repeat
i:=i+1;
now:=now+i*i*i mod 5+1;
for j:=(now-i*i*i mod 5) to now do
if pd[j]=false then now:=now+1;
if now>n then begin now:=1; i:=i-1; continue; end;
if pd[now]=false then repeat
now:=now+1;
if now>n then now:=1;
until pd[now]=true;
pd[now]:=false;
now:=now+1;
until i=m;
writeln(now-1);
end.
-
02016-08-21 21:03:38@
var
n,m,a,i:longint;
s:string;
begin
readln(n);
readln(m);
a:=1;
for i:=1 to n do s:=s+chr(i);
for i:=1 to m-1 do
if (a+((i*i*i) mod 5)+1)>n then
begin
a:=1;
a:=a+((i*i*i) mod 5)+1;
delete(s,a,1);
n:=n-1;
end
else
begin
a:=a+((i*i*i) mod 5)+1;
delete(s,a,1);
n:=n-1;
end;
if (a+((m*m*m) mod 5)+1)>n then a:=((m*m*m) mod 5)+2 else a:=a+((m*m*m) mod 5)+1;
write(ord(s[a]));
end. -
02016-08-18 23:43:11@
编译成功
foo.cpp: In function 'int main()':
foo.cpp:29:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(k>v.size())
^
测试数据 #0: Accepted, time = 15 ms, mem = 556 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 560 KiB, score = 10
Accepted, time = 15 ms, mem = 560 KiB, score = 100
```c++
/*
STL直接模拟即可,但是要注意呀
vector和数组一样开始元素是0,而第一个编号是1
一定要小心,总体还是挺简单的Powder
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;vector<int> v;
int k=1;
int n,m,ans;int main()
{
cin>>n>>m;
v.clear();
for(int i=1;i<=n;i++)
v.push_back(i);
for(int i=1;i<=m;i++)
{
int p=i*i*i%5+1;
k+=p;
if(k>v.size())
k=p+1;
if(i!=m)//第m次是跳到的位置,不能删除,需要判断
v.erase(v.begin()+k-1);//删除该位置
}
cout<<v[k-1]<<endl;//k应该-1
return 0;
}
``` -
02016-04-21 21:49:06@
水题一道
c++
var
n,m,a,i:longint;
s:string;
begin
readln(n);
readln(m);
a:=1;
for i:=1 to n do s:=s+chr(i);
for i:=1 to m-1 do
if (a+((i*i*i) mod 5)+1)>n then
begin
a:=1;
a:=a+((i*i*i) mod 5)+1;
delete(s,a,1);
n:=n-1;
end
else
begin
a:=a+((i*i*i) mod 5)+1;
delete(s,a,1);
n:=n-1;
end;
if (a+((m*m*m) mod 5)+1)>n then a:=((m*m*m) mod 5)+2 else a:=a+((m*m*m) mod 5)+1;
write(ord(s[a]));
end.
-
02016-02-27 10:53:10@
这简直是太坑人了 **明明第三个点应该是5的 **
后来的一定要看到....要不然会被坑死的
'''
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector <int >V;
int n,m,ans,pos=1;
int main()
{
cin>>n>>m;
for(int i=1;i<=n;++i)
V.push_back(i);
for(int i=1;i<=m;++i)
{
int k=i*i*i%5+1;
pos+=k;
if(pos>V.size())
pos=k+1;
ans=V[pos-1];
V.erase(lower_bound(V.begin(), V.end(), ans));
}
cout<<ans<<endl;
}
''' -
02016-01-06 18:35:01@
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define N 10001
int n,m;
int main()
{
scanf("%d %d",&n,&m);
int now=0;
for(int i=1;i<=m;i++)
{
now=now+(i*i*i)%5+2;
if(now>n)
{
now=now-n+1;
}
}
printf("%d",now);
return 0;
}
看哥的c++
不要谢我 -
02015-08-29 17:22:17@
暴力竟过。表无语。
-
02014-08-19 09:51:39@
= =样例都没过的程序...交上去竟然a了
#1要注意,类似于边界的东西吧
例如10 5这样的.... -
02014-03-23 21:08:41@
第50次AC,发个代码晒晒:
var
text:array [1..300] of longint;
head,now,i,j,n,m,t:longint;
begin
readln(n);
readln(m);
for i:=1 to n do text[i]:=i;
head:=n;
now:=1;
for i:=1 to m do
begin
now:=now+(i*i*i mod 5)+1;
while now>=head do
begin
now:=1;
now:=now+(i*i*i mod 5)+1;
end;
t:=text[now];
for j:=now to head do text[j]:=text[j]+1;
head:=head-1;
end;
writeln(t);
end. -
02014-01-24 23:11:37@
样例一直不过 幸亏看了题解里的提示 谢谢 AC了
var n,m,x,i,loc,s:longint;
a:array[1..200] of boolean;
b:array[1..200] of integer;
begin
readln(n);readln(m);
fillchar(a,sizeof(a),0);
for i:=1 to n do a[i]:=true;i:=0;loc:=1;
while i<m do
begin
i:=i+1;s:=0;
x:=i*i*i mod 5 +1;
repeat
inc(loc);
if a[loc] then inc(s);
if loc>n then begin loc:=1;s:=0;end;
until s=x;
b[i]:=loc;a[loc]:=false;while not a[loc] do inc(loc);
end;
write(b[i]);
end. -
02013-11-01 17:12:04@
发现了、从第一个位置、、汗,出题人小学语文没学好en?
-
02013-11-01 17:07:08@
为什么第一组会错?
-
02013-11-01 17:06:56@
var i,j,k:longint;
n,m:integer;
pos:integer;
num:array[1..200] of byte;
begin
readln(n,m);
pos:=1;
for i:=1 to n do num[i]:=i;k:=n;
for i:=1 to m-1 do begin
pos:=pos+((i mod 5)*(i mod 5)*(i mod 5)) mod 5+1;
if pos>k then begin pos:=0;pos:=pos+((i mod 5)*(i mod 5)*(i mod 5)) mod 5+1;end;
for j:=pos to n do num[j]:=num[j]+1;k:=k-1;
end;
pos:=pos+((m mod 5)*(m mod 5)*(m mod 5)) mod 5+1;
if pos>k then begin pos:=0;pos:=pos+((m mod 5)*(m mod 5)*(m mod 5)) mod 5+1;end;
writeln(num[pos]);end.
-
02013-10-18 21:41:05@
为什么我样例没过却AC了?
附上沙茶的程序
var
text:array [1..300] of longint;
head,now,i,j,n,m,t:longint;
begin
readln(n);
readln(m);
for i:=1 to n do text[i]:=i;
head:=n;
now:=1;
for i:=1 to m do
begin
now:=now+(i*i*i mod 5)+1;
while now>=head do
begin
now:=1;
now:=now+(i*i*i mod 5)+1;
end;
t:=text[now];
for j:=now to head do text[j]:=text[j]+1;
head:=head-1;
end;
writeln(t);
end.