zoukankan      html  css  js  c++  java
  • POJ 2359 Questions

    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[30010];
    
    int main()
    {
        string str;
        int n = 1999;
        int ans = 0;
        while(gets(temp))
        {
            str += temp;
        }
        int nLen = str.length();
        for (int i = 2; i <= nLen; i++)
        {
            ans = (ans + n) % i;
        }
        if (str[ans] == '?')
        {
            printf("Yes
    ");
        }
        else
        {
            if (str[ans] == ' ')
            {
                printf("No
    ");
            }
            else
            {
                printf("No comments
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    H50068:html页面清除缓存
    CSS0019: 样式中高度百分比无效时,这样写 height:calc(100%)
    H50067:body 背景颜色 背景图片 background 的 简写属性
    40、在last_update后面新增加一列名字为create_date
    39、使用强制索引查询
    38、针对actor表创建视图actor_name_view
    37、对first_name创建唯一索引uniq_idx_firstname,对last_name创建普通索引idx_lastname
    36、创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表
    35、批量插入如下数据,不使用replace操作
    34、批量插入如下数据
  • 原文地址:https://www.cnblogs.com/lzmfywz/p/3165988.html
Copyright © 2011-2022 走看看