Little Sheep and a paper解题报告
2013-07-15 22:06
387 查看
题目摘要: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,不知道怎么回事,算次方的时候用的是快速幂,时间绝对不会超时的,后来标程和数据出来,测试太大的数据就会出错,但还是不知道错在哪,到后来不得不换思路。
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,不知道怎么回事,算次方的时候用的是快速幂,时间绝对不会超时的,后来标程和数据出来,测试太大的数据就会出错,但还是不知道错在哪,到后来不得不换思路。
相关文章推荐
- BestCoder7 1002 Little Pony and Alohomora Part I(hdu 4986) 解题报告
- HUST——Little Sheep and a paper
- H~Little Sheep and a paper(13.7.11)
- 新生赛02 Problem F. Little Sheep and a paper
- BestCoder7 1001 Little Pony and Permutation(hdu 4985) 解题报告
- [第二次训练]Little Sheep and a paper
- 20130709 【南华大学 ACM】 新生赛第二场 【F. Little Sheep and a paper】
- 南华大学暑假个人练习 1015: Little Sheep and a paper
- hust Little Sheep and a paper
- HUST 1614 Little Sheep and a paper(数学题)
- HUST 1614 Little Sheep and a paper
- Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 解题报告
- 第四届吉林省大学生程序设计大赛个人解题报告 Problem J: Buying and Selling
- ACM之Ignatius and the Princess IV解题报告
- HDU1312 / POJ1979 / ZOJ2165 Red and Black(红与黑) 解题报告
- codeforces 476C.Dreamoon and Sums 解题报告
- 一中OJ #1434 序列的LCS [UVa 10635 -> Prince and Princess] | 动态规划 LCS映射转换LIS | 解题报告
- Codeforces Round #396 (Div. 2) E题Mahmoud and a xor trip(树状dp)解题报告
- Monkey and Banana(HDU 1069)解题报告(DP - 滚动数组)
- Partition Array by Odd and Even 解题报告