HDU5007
Post Robot
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 348 Accepted Submission(s): 274
Problem Description
DT is a big fan of digital products. He writes posts about technological products almost everyday in his blog.
But there is such few comments of his posts that he feels depressed all the day. As his best friend and an excellent programmer, DT asked you to help make his blog look more popular. He is so warm that you have no idea how to refuse. But you are unwilling to read all of his boring posts word by word. So you decided to write a script to comment below his posts automatically.
After observation, you found words “Apple” appear everywhere in his posts. After your counting, you concluded that “Apple”, “iPhone”, “iPod”, “iPad” are the most high-frequency words in his blog. Once one of these words were read by your smart script, it will make a comment “MAI MAI MAI!”, and go on reading the post.
In order to make it more funny, you, as a fan of Sony, also want to make some comments about Sony. So you want to add a new rule to the script: make a comment “SONY DAFA IS GOOD!” when “Sony” appears.
But there is such few comments of his posts that he feels depressed all the day. As his best friend and an excellent programmer, DT asked you to help make his blog look more popular. He is so warm that you have no idea how to refuse. But you are unwilling to read all of his boring posts word by word. So you decided to write a script to comment below his posts automatically.
After observation, you found words “Apple” appear everywhere in his posts. After your counting, you concluded that “Apple”, “iPhone”, “iPod”, “iPad” are the most high-frequency words in his blog. Once one of these words were read by your smart script, it will make a comment “MAI MAI MAI!”, and go on reading the post.
In order to make it more funny, you, as a fan of Sony, also want to make some comments about Sony. So you want to add a new rule to the script: make a comment “SONY DAFA IS GOOD!” when “Sony” appears.
Input
A blog article described above, which contains only printable characters(whose ASCII code is between 32 and 127), CR(ASCII code 13, ‘\r’ in C/C++), LF(ASCII code 10, ‘\n’ in C/C++), please process input until EOF. Note all characters are
case sensitive.
The size of the article does not exceed 8KB.
The size of the article does not exceed 8KB.
Output
Output should contains comments generated by your script, one per line.
Sample Input
Apple bananaiPad lemon ApplepiSony 233 Tim cook is doubi from Apple iPhoneipad iPhone30 is so biiiiiiig Microsoft makes good App.
Sample Output
MAI MAI MAI! MAI MAI MAI! MAI MAI MAI! SONY DAFA IS GOOD! MAI MAI MAI! MAI MAI MAI! MAI MAI MAI!
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
char s[2000005];
int main()
{
while(gets(s))
{
int len=strlen(s);
for(int i=0;i<len;i++)
{
if(s[i]=='A'&&s[i+1]=='p'&&s[i+2]=='p'&&s[i+3]=='l'&&s[i+4]=='e')
{
printf("MAI MAI MAI!\n");
}
if(s[i]=='i'&&s[i+1]=='P'&&s[i+2]=='h'&&s[i+3]=='o'&&s[i+4]=='n'&&s[i+5]=='e')
{
printf("MAI MAI MAI!\n");
}
if(s[i]=='i'&&s[i+1]=='P'&&s[i+2]=='a'&&s[i+3]=='d')
{
printf("MAI MAI MAI!\n");
}
if(s[i]=='i'&&s[i+1]=='P'&&s[i+2]=='o'&&s[i+3]=='d')
{
printf("MAI MAI MAI!\n");
}
if(s[i]=='S'&&s[i+1]=='o'&&s[i+2]=='n'&&s[i+3]=='y')
{
printf("SONY DAFA IS GOOD!\n");
}
}
}
return 0;
}
HDU5011
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 342 Accepted Submission(s): 264
Problem Description
Here is a game for two players. The rule of the game is described below:
● In the beginning of the game, there are a lot of piles of beads.
● Players take turns to play. Each turn, player choose a pile i and remove some (at least one) beads from it. Then he could do nothing or split pile i into two piles with a beads and b beads.(a,b > 0 and a + b equals to the number of beads of pile i after removing)
● If after a player's turn, there is no beads left, the player is the winner.
Suppose that the two players are all very clever and they will use optimal game strategies. Your job is to tell whether the player who plays first can win the game.
● In the beginning of the game, there are a lot of piles of beads.
● Players take turns to play. Each turn, player choose a pile i and remove some (at least one) beads from it. Then he could do nothing or split pile i into two piles with a beads and b beads.(a,b > 0 and a + b equals to the number of beads of pile i after removing)
● If after a player's turn, there is no beads left, the player is the winner.
Suppose that the two players are all very clever and they will use optimal game strategies. Your job is to tell whether the player who plays first can win the game.
Input
There are multiple test cases. Please process till EOF.
For each test case, the first line contains a postive integer n(n < 10 5) means there are n piles of beads. The next line contains n postive integer, the i-th postive integer a i(a i < 2 31) means there are a i beads in the i-th pile.
For each test case, the first line contains a postive integer n(n < 10 5) means there are n piles of beads. The next line contains n postive integer, the i-th postive integer a i(a i < 2 31) means there are a i beads in the i-th pile.
Output
For each test case, if the first player can win the game, ouput "Win" and if he can't, ouput "Lose"
Sample Input
1 1 2 1 1 3 1 2 3
Sample Output
Win Lose Lose
Source
2014 ACM/ICPC Asia Regional Xi'an Online
题意 : 取石子游戏,两个人轮流取石子,取石子有规则,要么那掉这堆石子,要么将这堆石子分成两堆,在加入原来的石堆当中,先手取完算胜利,否则失败。
思路:简单NIM,所有值异或为0,则跪,找规律找出来的= =。。。
Total Submission(s): 587 Accepted Submission(s): 367
不想多说,心塞塞的一题,用数学方法推也推出来了,一写MLE,后来别的队构造矩阵过了,然后自己就去构造了,很显然要加2维一个维护形如233这个值,另一个要加上当前元素的值,所以N+2阶的矩阵很好构造= =。。。忧桑,早知道早就去构造矩阵不用纯数学方法了,更心塞的是这题纯数学方法是能过的,不过那个大神开的求逆元的数组只开了11我却开了1E7+7不跪才怪了= =。。。
目测三个赛区都进了= =,不过深深感到我好酱油啊 不开森不开森啊= =。。。
题意 : 取石子游戏,两个人轮流取石子,取石子有规则,要么那掉这堆石子,要么将这堆石子分成两堆,在加入原来的石堆当中,先手取完算胜利,否则失败。
思路:简单NIM,所有值异或为0,则跪,找规律找出来的= =。。。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
long long a, sum;
int main()
{
while (~scanf("%d", &n))
{
sum = 0;
for (int i = 0 ; i < n; i++)
{
scanf("%I64d", &a);
sum ^= a;
}
if (sum == 0) printf("Lose\n");
else printf("Win\n");
}
return 0;
}
233 Matrix
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 587 Accepted Submission(s): 367
Problem Description
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233333 ... in the same meaning. And here is the question: Suppose we have a matrix called 233 matrix. In the first line, it would be 233, 2333, 23333... (it means a
0,1 = 233,a
0,2 = 2333,a
0,3 = 23333...) Besides, in 233 matrix, we got a
i,j = a
i-1,j +a
i,j-1( i,j ≠ 0). Now you have known a
1,0,a
2,0,...,a
n,0, could you tell me a
n,m in the 233 matrix?
Input
There are multiple test cases. Please process till EOF.
For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 10 9). The second line contains n integers, a 1,0,a 2,0,...,a n,0(0 ≤ a i,0 < 2 31).
For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 10 9). The second line contains n integers, a 1,0,a 2,0,...,a n,0(0 ≤ a i,0 < 2 31).
Output
For each case, output a
n,m mod 10000007.
Sample Input
1 1 1 2 2 0 0 3 7 23 47 16
Sample Output
234 2799 72937Hint![]()
Source
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
long long n,m;
const long long mod=(long long )(1e7+7);
long long b[25];
struct juzhen{
long long m[15][15];
};
juzhen mut(juzhen a,juzhen b)
{
juzhen c;
for(long long i=0;i<n+2;i++)
{
for(long long j=0;j<n+2;j++)
{
c.m[i][j]=0;
for(long long k=0;k<n+2;k++)
{
c.m[i][j]+=(a.m[i][k]*b.m[k][j])%mod;
c.m[i][j]%=mod;
}
}
}
return c;
}
juzhen power(juzhen a,long long p)
{
juzhen ans;
memset(ans.m,0,sizeof(ans.m));
for(long long i=0;i<n+2;i++)
{
ans.m[i][i]=1;
}
while(p)
{
if(p&1)
ans=mut(ans,a);
a=mut(a,a);
p>>=1;
}
return ans;
}
int main()
{
while(cin>>n>>m)
{
for(long long i=0;i<n;i++)
{
cin>>b[i];
}
b[n]=23;
b[n+1]=3;
juzhen ans;
memset(ans.m,0,sizeof(ans.m));
for(long long i=0;i<n;i++)
{
for(long long j=0;j<=i;j++)
{
ans.m[i][j]=1;
}
}
for(long long i=0;i<=n;i++)
{
ans.m[i][n]=10;
}
for(long long i=0;i<=n+1;i++)
{
ans.m[i][n+1]=1;
}
ans=power(ans,m);
long long res=0;
for(long long i=0;i<n+2;i++)
{
res+=ans.m[n-1][i]*b[i]%mod;
res%=mod;
}
cout<<res<<endl;
}
return 0;
}
目测三个赛区都进了= =,不过深深感到我好酱油啊 不开森不开森啊= =。。。