2013第四届

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.

输出

    For each test case, you should output the coordinate of C(x3,y3), the result should be rounded to 2 decimal places in a line.

示例输入

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?

输入

The first line of the input is a number T, which means the number of the test cases.

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

输出

For each question of each test case, please output the answer module 2012.

示例输入

122 1234

示例输出

20

提示

The expansion of the (2*x^(2^0) + 1) * (1*x^(2^1) + 1) is 1 + 2*x^1 + 1*x^2 + 2*x^3

来源

看题解才知道这题是怎么回事,正好每个x的指数都可以用二进制来表示,是1的话就将对应指数位置的系数相乘
#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. 

输入

 In the first line there is an integer T (1 < T <= 40), which indicates the number of test cases, and then T test cases follow. A test case contains seven integers n, A, K, a, b, m, P in one line.

1 <= n <= 10^6

0 <= A, K, a, b <= 10^9

1 <= m, P <= 10^9

输出

 For each case, the output format is “Case #c: ans”. 

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?

输入

    There are multiple test case in the input file, first line is a case number T. Each test case will begin with two integers N (0 <= N < 2001) and M (0 <= M < 10001), where N is the number of islands and M is number of portal. Next M lines each line contains two integers a and b, indicated there is a portal in island a that people can go from a to b by this portal. The island numbered from 1 to N.

输出

    For each test case, your output should be in one line with “Kalimdor is just ahead” (without quotes, hereinafter the same) if Thrall and Grom can meet or “The Burning Shadow consume us all” otherwise as indicated in the sample output. 

示例输入

23 21 21 33 21 22 3

示例输出

Case 1: The Burning Shadow consume us allCase 2: Kalimdor is just ahead

提示

这道题没看明白就过了。看了题解才知道是看是否两点能相连,答案DFS
#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 ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code any time. Here you need to write a contest print server to handle all the requests.

输入

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.

输出

    Every time a request is completed or the printer is break down,you should output one line like "p pages for Team_Name",p is the number of pages you give the team "Team_Name".

    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?


输入

There are no more than 70 test cases. 
 
In each case , first Input a positive integer n(0
The input is terminated with 0. This test case is not to be processed.

输出

Please calculate the expected number of steps required to reach the KEY room, there are 2 digits after the decimal point.

示例输入

3
0.3 0.7
0.1 0.3 0.6
0 

示例输出

3.41

提示

 

来源

2013年山东省第四届ACM大学生程序设计竞赛

示例程序


 第一次接触期望DP,还挺有意思的,就是倒推;

#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  
**************************************/




 
  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值