Rescue The Princess
Time Limit: 1000MS Memory limit: 65536K
题目描述
Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry the princess set out immediately. Yet, the beast set a maze. Only if the prince find out the maze’s exit can he save the princess.
Now, here comes the problem. The maze is a dimensional plane. The beast is smart, and he hidden the princess snugly. He marked two coordinates of an equilateral triangle in the maze. The two marked coordinates are A(x1,y1) and B(x2,y2). The third coordinate C(x3,y3) is the maze’s exit. If the prince can find out the exit, he can save the princess. After the prince comes into the maze, he finds out the A(x1,y1) and B(x2,y2), but he doesn’t know where the C(x3,y3) is. The prince need your help. Can you calculate the C(x3,y3) and tell him?
输入
The first line is an integer T(1 <= T <= 100) which is the number of test cases. T test cases follow. Each test case contains two coordinates A(x1,y1) and B(x2,y2), described by four floating-point numbers x1, y1, x2, y2 ( |x1|, |y1|, |x2|, |y2| <= 1000.0).
Please notice that A(x1,y1) and B(x2,y2) and C(x3,y3) are in an anticlockwise direction from the equilateral triangle. And coordinates A(x1,y1) and B(x2,y2) are given by anticlockwise.
输出
示例输入
4 -100.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 0.00 0.00 100.00 100.00 1.00 0.00 1.866 0.50
示例输出
(-50.00,86.60) (-86.60,50.00) (-36.60,136.60) (1.00,1.00)
提示
Alice and Bob
Time Limit: 1000MS Memory limit: 65536K
题目描述
Alice and Bob like playing games very much.Today, they introduce a new game.
There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1). Then Alice ask Bob Q questions. In the expansion of the Polynomial, Given an integer P, please tell the coefficient of the x^P.
Can you help Bob answer these questions?
输入
For each case, the first line contains a number n, then n numbers a0, a1, .... an-1 followed in the next line. In the third line is a number Q, and then following Q numbers P.
1 <= T <= 20
1 <= n <= 50
0 <= ai <= 100
Q <= 1000
0 <= P <= 1234567898765432
输出
示例输入
122 1234
示例输出
20
提示
来源
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int a[60];
int main()
{
int t,n;
scanf("%d%d",&t,&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int m;
scanf("%d",&m);
int sum;
while(m--)
{
long long p;
scanf("%lld",&p);
if(p>=pow(2,n)) { sum=0;break;}
sum=1;
int j=1;
while(p!=0)
{
sum=sum*a[j];
j++;
p=p/2;
}
printf("%d\n",sum);
}
return 0;
}
A^X mod P
Time Limit: 5000MS Memory limit: 65536K
题目描述
It's easy for ACMer to calculate A^X mod P. Now given seven integers n, A, K, a, b, m, P, and a function f(x) which defined as following.
f(x) = K, x = 1
f(x) = (a*f(x-1) + b)%m , x > 1
Now, Your task is to calculate
( A^(f(1)) + A^(f(2)) + A^(f(3)) + ...... + A^(f(n)) ) modular P.
输入
1 <= n <= 10^6
0 <= A, K, a, b <= 10^9
1 <= m, P <= 10^9
输出
c is the case number start from 1.
ans is the answer of this problem.
示例输入
23 2 1 1 1 100 1003 15 123 2 3 1000 107
示例输出
Case #1: 14Case #2: 63
提示
Thrall’s Dream
Time Limit: 1000MS Memory limit: 65536K
题目描述
We never paid any heed to the ancient prophecies, like fools we clung to the old hatreds, and fought as we had for generations. Until one day the sky rained fire, and a new enemy came upon us. We stand now upon the brink of destruction, for the Reign of Chaos has come at last.
Thrall, the warchief of the Orcish Horde, all along, he led his tribe live in the fringe of Lordaeron under the human control. In a downpour night, Thrall falls into sleep in a Orc hall at Arathi Highlands, at this moment he heard a voice:
“The sands of time have run out, son of Durotan. The cries of war echo upon the winds, the remnants of the past scar the land which is besieged once again by conflict. Heroes arise to challenge fate, and lead their brethren to battle. As mortal armies rush blindly towards their doom, The Burning Shadow comes to consume us all. You must rally the Horde, and lead your people to their destiny.
I will answer all of your questions in time, young warchief. For now, rally your warriors and prepare to leave this land, cross the sea to the distant land of Kalimdor. We will speak again. ”
Thrall believes the prophesy of Blood Raven Medivh. Three days later, He and Grom Hellscream's Warsong Clan meet in the Lordaeron coast to the distant lands of Kalimdor. But the Goblin Zeppelins they take encountered storms in the middle. Thrall and Grom falling to the islands, they want to find each other and then to Kalimdor.
For the sake of simplicity, we assume that Thrall and Grom may fall into any islands x and y, only by Thrall to find Grom or by Grom to find Thrall. Give you the map of this island, please judge that Thrall and Gtom can meet?
输入
输出
示例输入
23 21 21 33 21 22 3
示例输出
Case 1: The Burning Shadow consume us allCase 2: Kalimdor is just ahead
提示
#include <iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
vector<int >mm[2005];
int visit[2005][2005];
int n;
void dfs(int x,int y)
{
if(mm[y].size()==0) return;
for(int i=0;i<mm[y].size();i++)
if(visit[x][mm[y][i]]==0)
{
visit[x][mm[y][i]]=1;
dfs(x,mm[y][i]);
}
}
int main()
{
int t;
scanf("%d",&t);
int count=0;
while(t--)
{
int m,a,b;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
mm[i].clear();
for(int i=0;i<m;i++)
{
scanf("%d%d",&a,&b);
mm[a].push_back(b);
}
memset(visit,0,sizeof(visit));
for(int i=1;i<=n;i++) visit[i][i]=1;//cout<<"wrong";
for(int i=1;i<=n;i++)
dfs(i,i);
/* for(int i=1;i<=n;i++)
{ for(int j=1;j<=n;j++)
cout<<visit[i][j]<<" ";
cout<<endl;
}*/
int flag=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
if(visit[i][j]==0&&visit[j][i]==0)
{
flag=0;
break;
}
if(!flag) break;
}
if(!flag) printf("Case %d: The Burning Shadow consume us all\n",++count);
else printf("Case %d: Kalimdor is just ahead\n",++count);
}
return 0;
}
Contest Print Server
Time Limit: 1000MS Memory limit: 65536K
题目描述
输入
In each case,the first line contains 5 integers n,s,x,y,mod (1<=n<=100, 1<=s,x,y,mod<=10007), and n lines of requests follow. The request is like "Team_Name request p pages" (p is integer, 0<p<=10007, the length of "Team_Name" is no longer than 20), means the team "Team_Name" need p pages to print, but for some un-know reason the printer will break down when the printed pages counter reached s(s is generated by the function s=(s*x+y)%mod ) and then the counter will become 0. In the same time the last request will be reprint from the very begin if it isn't complete yet(The data guaranteed that every request will be completed in some time).
You can get more from the sample.
输出
Please note that you should print an empty line after each case.
示例输入
23 7 5 6 177Team1 request 1 pagesTeam2 request 5 pagesTeam3 request 1 pages3 4 5 6 177Team1 request 1 pagesTeam2 request 5 pagesTeam3 request 1 pages
示例输出
1 pages for Team15 pages for Team21 pages for Team31 pages for Team13 pages for Team25 pages for Team21 pages for Team3
提示
<pre name="code" class="cpp">#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char t[105][100];
int a[105];
int main()
{
int tt;
scanf("%d",&tt);
while(tt--)
{
int n,s,x,y,mod;
char request[100],page[100];
scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod);
for(int i=1;i<=n;i++)
{
scanf("%s",t[i]);
scanf("%s",request);
scanf("%d",&a[i]);
scanf("%s",page);
}
// cout<<"1"<<t[1]<<"1"<<endl;
// for(int i=1;i<=n;i++)
// cout<<t[i]<<" "<<request<<" "<<num[i]<<endl;
int count=0,pos=1,k=1,sum=0;
int flag=0,shengyu;
while(k<n+1)
{
for(k=pos;k<=n;k++)
{
if(count+a[k]>=s)
{
flag=1;
break;
}
sum=sum+a[k];
count+=a[k];
printf("%d pages for %s\n",a[k],t[k]);
}
if(flag==1)
{
shengyu=a[k]-(s-sum); //µ½countÊ£ÓàµÄ
if(shengyu==0) { printf("%d pages for %s\n",a[k],t[k]);k++;pos=k;}
else
{
printf("%d pages for %s\n",s-sum,t[k]);
pos=k;
}
s=(((s%mod)*(x%mod)%mod)+y%mod)%mod;
s=(s*x+y)%mod;
count=0;
sum=0;
flag=0;
}
}
printf("\n");
}
return 0;
}
/**************************************
Problem id : SDUT OJ 2624
User name : xiaopp
Result : Wrong Answer
Take Memory : 528K
Take Time : 0MS
Submit Time : 2015-04-30 15:58:40
**************************************/
The number of steps
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two rooms,the third layer have three rooms …). Now she stands at the top point(the first layer), and the KEY of this maze is in the lowest layer’s leftmost room. Known that each room can only access to its left room and lower left and lower right rooms .If a room doesn’t have its left room, the probability of going to the lower left room and lower right room are a and b (a + b = 1 ). If a room only has it’s left room, the probability of going to the room is 1. If a room has its lower left, lower right rooms and its left room, the probability of going to each room are c, d, e (c + d + e = 1). Now , Mary wants to know how many steps she needs to reach the KEY. Dear friend, can you tell Mary the expected number of steps required to reach the KEY?
输入
输出
示例输入
3 0.3 0.7 0.1 0.3 0.6 0
示例输出
3.41
提示
来源
示例程序
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
double dp[150][150];
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n)
{
memset(dp,0,sizeof(dp));
double a,b,c,d,e;
scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e);
// cout<<"wrong";
for(int j=2;j<=n;j++)
dp[n][j]+=1*(dp[n][j-1]+1);
for(int i=n-1;i>=1;i--)
{
dp[i][1]+=a*(dp[i+1][1]+1)+b*(dp[i+1][2]+1);
for(int j=2;j<=i;j++)
dp[i][j]+=e*(dp[i][j-1]+1)+c*(dp[i+1][j]+1)+d*(dp[i+1][j+1]+1);
}
printf("%0.2lf\n",dp[1][1]);
}
return 0;
}
/**************************************
Problem id : SDUT OJ 2623
User name : xiaopp
Result : Accepted
Take Memory : 752K
Take Time : 0MS
Submit Time : 2015-05-01 16:40:22
**************************************/