Questions
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1228   Accepted: 449

Description

Holding a collegiate programming contest is a very exhausting work. There is a well-known proverb that one fool can ask so many questions that a hundred clever men will not answer. And during a collegiate programming contest questions are asked by one hundred clever people.

The jury of the Third Urals Collegiate Programming Contest being clever enough has found a simple way to make its work easier. We have invented a simple algorithm that will help us answer ALL your numerous questions! Moreover, this algorithm guarantees that the same questions will have the same answers (this would be hardly possible, if we would undertook such a task ourselves). According to this algorithm a member of the jury starts to delete characters of the question in the following order: 

  1. Starting from the first character he or she counts out N-1 characters (spaces, punctuation marks etc. are considered to be characters too) and deletes the Nth character.
  2. If a string ends the count continues from the beginning of the string.
  3. After deleting a character the count restarts from the character that would be the (N+1)-st in the previous count.
  4. If the last remaining character is a question-mark ("?") then the answer to the question is "Yes". If it is a space then the answer is "No". Any other character will lead to "No comments" answer.

You should help the jury and write a program that will do a hard work of answering your questions tomorrow. The number N is secret and will not be announced even after the end of the contest. Your program should use N=1999.

For example, taking a string "Is it a good question?" (its length is 22) the characters will be counted in the following way: "Is it a good question?Is it ... quest" and "i" will be deleted. Then the count restarts from "on?Is it..." etc., until "s" will be left (thus the answer is "No comments", as usual).

Input

The input is a question, that is any text file containing at least one character (end of line is not a character). Each character of the input (excepting the ends of lines) is a part of the question. 
The size of the input file is not more than 30000.

Output

The answer.

Sample Input

Sample input #1
Does the jury of this programming contest use the
algorithm described in this problem to answer my questions? Sample input #2
At least, will anybody READ my question? Sample input #3
This is
UNFAIR!

Sample Output

Sample output #1
Yes Sample output #2
No Sample output #3
No comments

解题方法:约瑟夫问题,直接套用递推公式。

#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std; char temp[]; int main()
{
string str;
int n = ;
int ans = ;
while(gets(temp))
{
str += temp;
}
int nLen = str.length();
for (int i = ; i <= nLen; i++)
{
ans = (ans + n) % i;
}
if (str[ans] == '?')
{
printf("Yes\n");
}
else
{
if (str[ans] == ' ')
{
printf("No\n");
}
else
{
printf("No comments\n");
}
}
return ;
}

POJ 2359 Questions的更多相关文章

  1. POJ 2359 Questions(约瑟夫环——数学解法)

    题目链接: http://poj.org/problem?id=2359 题意描述: 输入一个字符串 按照下面的规则,如果剩下的最后一个字符是'?',输出"Yes",如果剩下的最后 ...

  2. Poj 2371 Questions and answers(排序)

    题目链接:http://poj.org/problem?id=2371 思路分析:使用计数排序或其他时间复杂度为O( log N )的排序. 代码如下: #include <iostream&g ...

  3. [划分树] POJ 2104 K-th Number

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 51732   Accepted: 17722 Ca ...

  4. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  5. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  6. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  7. 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733

    1.POJ 1733 Parity game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5744   Accepted: ...

  8. 【POJ】2104 K-th Number(区间k大+主席树)

    http://poj.org/problem?id=2104 裸题不说.主席树水过. #include <cstdio> #include <iostream> #includ ...

  9. POJ 2104&HDU 2665 Kth number(主席树入门+离散化)

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 50247   Accepted: 17101 Ca ...

随机推荐

  1. Django2.0路由补充之path,re_path及视图层

    以下是Django2.0版本 正则捕获到的参数都是字符串,所以如果函数需要用的其他数据类型,可以在函数中直接转换,也可以在路由中直接转换,如下: 下面实例是匹配整数,传过去的参数就是整数 from d ...

  2. http协议参数详解

    整理一下http协议中的一些参数详解 截取了一个当前项目中的请求作为示例: Genaral:通用头 Request URL:当前请求的请求地址 Request Method:请求类型 get.post ...

  3. 生鲜o2o配送应用系统,包括Android源码+SSH带后台管理系统

    前台功能划分    我的 登录            账户+密码 注册            订单管理 查看/删除(显示订单详情)                支付(提交订单)           ...

  4. debug1: expecting SSH2_MSG_KEX_ECDH_REPLY解决

    设置mtu ifconfig en1 mtu 1200 代理工具 退出lantern,退出shadowsocks

  5. UVA - 12264 Risk (二分,网络流)

    题意比较坑,移动完以后的士兵不能再次移动,不然样例都过不了... 最小值最大满足决策单调性所以二分答案,跑网络流验证是否可行. 这种题重点在建图,为了保证只移动一次,拆点,一个入点一个出点,到了出点的 ...

  6. python基础一 day14 复习

    迭代器和生成器迭代器:双下方法 : 很少直接调用的方法.一般情况下,是通过其他语法触发的可迭代的 —— 可迭代协议 含有__iter__的方法('__iter__' in dir(数据))可迭代的一定 ...

  7. django 2.0 + pycharm2017 出现的问题

    在创建完成app之后,在models文件里创建两个类:BlogType , Blog, 创建超级用户,注册admin,在登陆admin之后发现,发现 BlogType , Blog,并没有导入到adm ...

  8. JS实现跑马灯效果(向左,向上)

    <html> <head> <title>JS实现跑马灯效果</title> <style> * { font-size:12px; fon ...

  9. var、let、const声明变量的区别

    let和var声明变量的区别:1.let所声明的变量只在let命令所在的代码块内有效.(块级作用域) for(let i=0;i<10;i++){ // ... } console.log(i) ...

  10. Java递归获取部门树 返回jstree数据

    @GetMapping("/getDept")@ResponseBodypublic Tree<DeptDO> getDept(String deptId){ Tree ...