Little Sheep and a paper解题报告
来源:互联网 发布:php防注入代码 编辑:程序博客网 时间:2024/05/22 04:24
题目摘要:One day, Little Sheep gets anAK(all kill) in a contest, so he is very boring, then he just plays with a paper.The paper has two faces called A and B. Sheep _nds the paper can be folded forin_nity times,and now Sheep thinks the paper is interesting, so he tries tofold the paper in half for many times. He finds out he has four way to make thepaper folded in half, there are listed below:
At first, Little Sheep keeps the face A ofthe paper faced to him,and he fold the paper for many times.In the end, Sheepopens up the paper, and keeps the face A faced to him again. Now the questionis :How many creases on the face A of the paper are protruding? God sheepsolves the question without 2 seconds. Can you? You should make your answer mod100000009.
题目大意:折纸游戏,按照规定,有四种折纸方式,给出一串折纸方式,求纸面A的凸起折痕数。
输入输出要求:
Input
The first line of input contains a singlepositive integer N , which means the number of test cases.
The following N lines gives N non-emptystrings containing only characters in "UDLR", which is the sequencesof the actions of the Sheep to fold paper. The length of the each string is apositive number less than 106.
Output
For each case output the answer mod100000009 in a line.
输入输出样例:
Sample input
4
L
LR
DLUR
ULULL
Sample output
0
1
10
22
解题思路:根据纸被折成的份数来解决问题,假设竖着折,折一下面被分成2份,凸起为0,折两下面被分成4份,凸起为1,即2的1次方减一。折三下面被分成8份,凸起为3,即2的2次方减一。在竖着折的同时,每横着折一次,竖着的折痕翻倍。横着折同理。
代码:
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=1000000+5;
const int mod=100000009;
char str[maxn];
int main()
{
intN;
cin>>N;
while(N--)
{
cin>>str;
longint h=0,v=0;
intm=1;
for(inti=0;i<strlen(str);i++)
{
if((str[i]=='R')||(str[i]=='L'))
{
h=(h+m/2)%mod;
v=2*v%mod;
}
else
{
v=(v+m/2)%mod;
h=2*h%mod;
}
m=2*m;
m=m%(2*mod);
}
cout<<(h+v)%mod<<endl;
}
return0;
}
解题感想:开始套公式算,测试样例都过了,就是WA,不知道怎么回事,算次方的时候用的是快速幂,时间绝对不会超时的,后来标程和数据出来,测试太大的数据就会出错,但还是不知道错在哪,到后来不得不换思路。
- Little Sheep and a paper解题报告
- HUST 1614 Little Sheep and a paper
- [第二次训练]Little Sheep and a paper
- HUST——Little Sheep and a paper
- H~Little Sheep and a paper(13.7.11)
- 20130709 【南华大学 ACM】 新生赛第二场 【F. Little Sheep and a paper】
- 南华大学暑假个人练习 1015: Little Sheep and a paper
- ZQUOJ1396 Rock, Scissors, Paper 解题报告
- CF 453B Little Pony and Harmony Chest 解题报告(状态压缩DP)
- Paper Outline and a template
- codeforces 682 a 解题报告 Alyona and Numbers 数论基础
- A - SnowflakeSnowSnowflakes解题报告
- How to Read a Paper -- 阅读报告
- A. Little Elephant and Function
- A. Little Elephant and Chess
- A. Little Elephant and Rozdil
- A. Little Elephant and Bits
- A. Little Elephant and Bits
- NYOJ 483.Nightmare
- Hibernate3和4版本的不同
- 读王爽老师汇编语言笔记---int指令、端口、外中断以及键盘的输入
- 砖1 伙伴算法
- Get、Post、requert提交冲突时是怎么执行?
- Little Sheep and a paper解题报告
- 北京联创智融信息技术有限公司 2013校园招聘 java笔试面试
- 国内各大互联网公司相关技术站点2.0版 (集合腾讯、阿里、百度、搜狐、新浪、360等共49个)
- ubuntu 12.04 samba
- 哈希表实验C语言版
- 给Javafx2表格中加超链接hyperlink
- onbeforeunload与onunload事件
- c语言要点摘录(15~20)
- C和JAVA中数组的区别