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

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

Sample Output

  1. Sample output #1
  2. Yes
  3.  
  4. Sample output #2
  5. No
  6.  
  7. Sample output #3
  8. No comments

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

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. char temp[];
  7.  
  8. int main()
  9. {
  10. string str;
  11. int n = ;
  12. int ans = ;
  13. while(gets(temp))
  14. {
  15. str += temp;
  16. }
  17. int nLen = str.length();
  18. for (int i = ; i <= nLen; i++)
  19. {
  20. ans = (ans + n) % i;
  21. }
  22. if (str[ans] == '?')
  23. {
  24. printf("Yes\n");
  25. }
  26. else
  27. {
  28. if (str[ans] == ' ')
  29. {
  30. printf("No\n");
  31. }
  32. else
  33. {
  34. printf("No comments\n");
  35. }
  36. }
  37. return ;
  38. }

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. 2840 WIKIOI——评测

    2840 WIKIOI——评测 时间限制: 1 s 空间限制: 2000 KB 题目等级 : 白银 Silver       题目描述 Description Wikioi上有一题有N个测试点,时限为 ...

  2. JS实现的图片预览功能

    之前的博文有实现过图片上传预览,但那种方法是预览时就将图片上传,会产生很大的浪费空间.找到了之前有人写的用JS实现的图片预览,就说用js将上传的图片显示,上传代码在之前的博文中有写到. 以下是实现的代 ...

  3. jquery.qrcode.min.js生成二维码

    jquery.qrcode.min.js是一款可以生成二维码的插件,使用前提是先引入jquery,因为jquery.qrcode.min.js依赖jquery. 基本用法 1.引入js <scr ...

  4. Obj-C Memory Management

    Memory management is one of the most important process in any programming language. It is the proces ...

  5. 对于HDMI设备连接状态的监听

    对与最近主要做的是电视机盒子端的开发,其中涉及到设备的状态监听比较繁琐,所以对HDMI的连接状态的监听方法做个记录,方便后续查看. 主要通过两种方式: (1)比较常用的广播监听 注册一个动态广播来获取 ...

  6. Jenkins执行shell脚本启动tomcat失败解决方法

    环境:Centos 7 Jenkins版本:2.124 状况:Jenkins会执行服务器某个目录下的Shell, 脚本中功能是复制替换某两个配置文件,然后关闭tomcat,重启Tomcat. 但是,T ...

  7. (转)UVM挑战及概述

    UVM的调度也具有其独特的挑战,尤其是在调试的领域.其中的一些挑战如下: 1. Phase的管理:objections and synchronization 2. 线程调试 3. Tracing i ...

  8. uvm_env——UVM大环境(UVM Environment )

    1 What is uvm_env? uvm_env is used to create and connect the uvm_components like driver, monitors , ...

  9. 用YII实现多重查询(基于tag)

    场景: 有一个饭店表 restaurant,存放所有饭店记录.我需要一个功能,将饭店按照不同的条件进行多重查询.就象这样:   氛围:浪漫 / 商务会谈 / 茅草屋 菜系:川菜 / 鲁菜 / 家常菜. ...

  10. 爬虫基本原理及requests,response详解

    一.爬虫基本原理 1.爬虫是什么 #1.什么是互联网? 互联网是由网络设备(网线,路由器,交换机,防火墙等等)和一台台计算机连接而成,像一张网一样. #2.互联网建立的目的? 互联网的核心价值在于数据 ...