POJ 2359 Questions
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1228 | Accepted: 449 |
Description
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:
- 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.
- If a string ends the count continues from the beginning of the string.
- After deleting a character the count restarts from the character that would be the (N+1)-st in the previous count.
- 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 size of the input file is not more than 30000.
Output
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的更多相关文章
- POJ 2359 Questions(约瑟夫环——数学解法)
题目链接: http://poj.org/problem?id=2359 题意描述: 输入一个字符串 按照下面的规则,如果剩下的最后一个字符是'?',输出"Yes",如果剩下的最后 ...
- Poj 2371 Questions and answers(排序)
题目链接:http://poj.org/problem?id=2371 思路分析:使用计数排序或其他时间复杂度为O( log N )的排序. 代码如下: #include <iostream&g ...
- [划分树] POJ 2104 K-th Number
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 51732 Accepted: 17722 Ca ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733
1.POJ 1733 Parity game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5744 Accepted: ...
- 【POJ】2104 K-th Number(区间k大+主席树)
http://poj.org/problem?id=2104 裸题不说.主席树水过. #include <cstdio> #include <iostream> #includ ...
- POJ 2104&HDU 2665 Kth number(主席树入门+离散化)
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 50247 Accepted: 17101 Ca ...
随机推荐
- Django2.0路由补充之path,re_path及视图层
以下是Django2.0版本 正则捕获到的参数都是字符串,所以如果函数需要用的其他数据类型,可以在函数中直接转换,也可以在路由中直接转换,如下: 下面实例是匹配整数,传过去的参数就是整数 from d ...
- http协议参数详解
整理一下http协议中的一些参数详解 截取了一个当前项目中的请求作为示例: Genaral:通用头 Request URL:当前请求的请求地址 Request Method:请求类型 get.post ...
- 生鲜o2o配送应用系统,包括Android源码+SSH带后台管理系统
前台功能划分 我的 登录 账户+密码 注册 订单管理 查看/删除(显示订单详情) 支付(提交订单) ...
- debug1: expecting SSH2_MSG_KEX_ECDH_REPLY解决
设置mtu ifconfig en1 mtu 1200 代理工具 退出lantern,退出shadowsocks
- UVA - 12264 Risk (二分,网络流)
题意比较坑,移动完以后的士兵不能再次移动,不然样例都过不了... 最小值最大满足决策单调性所以二分答案,跑网络流验证是否可行. 这种题重点在建图,为了保证只移动一次,拆点,一个入点一个出点,到了出点的 ...
- python基础一 day14 复习
迭代器和生成器迭代器:双下方法 : 很少直接调用的方法.一般情况下,是通过其他语法触发的可迭代的 —— 可迭代协议 含有__iter__的方法('__iter__' in dir(数据))可迭代的一定 ...
- django 2.0 + pycharm2017 出现的问题
在创建完成app之后,在models文件里创建两个类:BlogType , Blog, 创建超级用户,注册admin,在登陆admin之后发现,发现 BlogType , Blog,并没有导入到adm ...
- JS实现跑马灯效果(向左,向上)
<html> <head> <title>JS实现跑马灯效果</title> <style> * { font-size:12px; fon ...
- var、let、const声明变量的区别
let和var声明变量的区别:1.let所声明的变量只在let命令所在的代码块内有效.(块级作用域) for(let i=0;i<10;i++){ // ... } console.log(i) ...
- Java递归获取部门树 返回jstree数据
@GetMapping("/getDept")@ResponseBodypublic Tree<DeptDO> getDept(String deptId){ Tree ...