URAL 1098 Questions <约瑟夫环>
2016-07-06 09:19
465 查看
题意:说一句话,系统进行回复。周期N = 1999,每次遍历一遍字符串(字长不够N,从头循环),找到第N个剔除。找到最后一次剩余的字符。1.若为‘?’,输出Yes2.若为‘ ‘,输出No3.其余情况,输出No comments样例:
input | output |
---|---|
Does the jury of this programming contest use the algorithm described in this problem to answer my questions? | Yes |
At least, will anybody READ my question? | No |
This is UNFAIR! | No comments |
#include<iostream>#include<cstdio>using namespace std;char str[30003];int fun(int m,int k,int i)//以k为周期,m长度,第i次,输出的编号(0,1,2,...,m-1){if(i==1)return (m+k-1)%m;elsereturn (fun(m-1,k,i-1)+k)%m;}int main(){//freopen("in.txt","r",stdin);int len=0;while(scanf("%c",&str[0])!=EOF){if(str[0]>=' '){str[++len]=str[0];//printf(" c = %c\n",str[0]);}}int k=fun(len,1999,len) +1;//printf("str[%d] = %c\n",k,str[k]);if (str[k]=='?')printf("Yes\n");else if (str[k]==' ')printf("No\n");elseprintf("No comments\n");return 0;}
相关文章推荐
- SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <1MB model size阅读笔记
- 最新SqueezeNet 模型详解,CNN模型参数降低50倍,压缩461倍!
- mvc easyui extjs
- 116. N-Queens
- Android MessageQueue与Message详解
- .NET平台开源项目速览(17)FluentConsole让你的控制台酷起来
- HDU 5288 OO’s Sequence (数论)
- pyhton中的Queue(队列)
- 易语言UI设计体会
- BZOJ2656 [Zjoi2012]数列(sequence)
- easyui
- Random Number Series Questions
- Unique Paths | & ||
- Binary Tree Longest Consequence
- N-Queens | & N-Queens II
- MySQL: Tree-Hierarchical query
- 陶哲轩实分析-第18章 Lebesgue测度
- Range Sum Query 2D
- Next Larger Value in BST
- LeetCode--No.357--Count Numbers with Unique Digits