2013长沙现场赛三道铜牌题目

来源:互联网 发布:端口号查询 编辑:程序博客网 时间:2024/04/27 14:22

Alice's Print Service

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her print service found some tricks to save money.

For example, the price when printing less than 100 pages is 20 cents per page, but when printing not less than 100 pages, you just need to pay only 10 cents per page. It's easy to figure out that if you want to print 99 pages, the best choice is to print an extra blank page so that the money you need to pay is 100 × 10 cents instead of 99 × 20 cents.

Now given the description of pricing strategy and some queries, your task is to figure out the best ways to complete those queries in order to save money.

Input

The first line contains an integer T (≈ 10) which is the number of test cases. Then T cases follow.

Each case contains 3 lines. The first line contains two integers n, m (0 < n, m ≤ 105). The second line contains 2n integers s1, p1, s2, p2, ..., sn, pn (0=s1 < s2 < ... < sn ≤ 109, 109 ≥ p1 ≥ p2 ≥ ... ≥ pn ≥ 0). The price when printing no less than si but less than si+1 pages is pi cents per page (for i=1..n-1). The price when printing no less than sn pages is pn cents per page. The third line containing m integers q1 .. qm (0 ≤ qi ≤ 109) are the queries.

Output

For each query qi, you should output the minimum amount of money (in cents) to pay if you want to print qi pages, one output in one line.

Sample Input

12 30 20 100 100 99 100

Sample Output

010001000

Author: ZHUANG, Junyuan
Contest: The 2013 ACM-ICPC Asia Changsha Regional Contest


题目大意: 打印k页的资料,给出n中付费方案,一次打印超过s1但不超过s2的每页收费p1,超过s2不超过s3的收费p2.....数据保证0=s1<s2<...<sn,p1>=p1>=p3>=...>=pn。接下来m个查询,对于每个查询问最少花多少钱?例如s1=0 s2=100  p1=20 p2=10 的时候,若要打印99页,显然直接打印100页要更便宜一点..所以结果是1000..

解题思路:比赛的时候一个多小时才出的这个题目,当时最终A的程序是用了二分加上RMQ查询,其实可以先预处理,然后再二分查找,不过自己的二分代码还是太次了。详见代码。

题目地址:Alice's Print Service

AC代码:
#include<iostream>#include<cstdio>using namespace std;const int maxn=100005;int n,q;int s[maxn];int v[maxn];long long val[maxn];int bitsearch(int x)  //二分还是写得很次{    int l,r,mid;    l=1,r=n;    mid=(l+r)>>1;    while(l<r)    {        if(l==r-1)        {            if(s[r]<x)            {                mid=r;                break;            }            else            {                mid=l;                break;            }        }        if(s[mid]<x) l=mid;        else r=mid-1;        mid=(l+r)>>1;    }    return mid;}int main(){    int tes,i;    cin>>tes;    int a,b,tmp;    while(tes--)    {       scanf("%d%d",&n,&q);       for(i=1;i<=n;i++)       {           scanf("%d%d",&a,&b);           s[i]=a;           v[i]=b;           val[i]=(long long)a*b;       }       for(i=n-1;i>=1;i--)           val[i]=min(val[i],val[i+1]);       for(i=1;i<=q;i++)       {           scanf("%d",&tmp);           if(tmp>=s[n]) printf("%lld\n",(long long)tmp*v[n]);           else           {               int ans = bitsearch(tmp);               //cout<<ans<<endl;               int t=min(n,ans+1);               long long res= min ((long long)tmp*v[ans],val[t]);               printf("%lld\n",res);           }       }    }    return 0;}


做出A题之后就开始看出的第二多的,J题
Josephina and RPG

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

A role-playing game (RPG and sometimes roleplaying game) is a game in which players assume the roles of characters in a fictional setting. Players take responsibility for acting out these roles within a narrative, either through literal acting or through a process of structured decision-making or character development.

Recently, Josephina is busy playing a RPG named TX3. In this game, M characters are available to by selected by players. In the whole game, Josephina is most interested in the "Challenge Game" part.

The Challenge Game is a team play game. A challenger team is made up of three players, and the three characters used by players in the team are required to be different. At the beginning of the Challenge Game, the players can choose any characters combination as the start team. Then, they will fight with N AI teams one after another. There is a special rule in the Challenge Game: once the challenger team beat an AI team, they have a chance to change the current characters combination with the AI team. Anyway, the challenger team can insist on using the current team and ignore the exchange opportunity. Note that the players can only change the characters combination to the latest defeated AI team. The challenger team get victory only if they beat all the AI teams.

Josephina is good at statistics, and she writes a table to record the winning rate between all different character combinations. She wants to know the maximum winning probability if she always chooses best strategy in the game. Can you help her?

Input

There are multiple test cases. The first line of each test case is an integer M (3 ≤ M ≤ 10), which indicates the number of characters. The following is a matrix T whose size is R × RR equals to C(M, 3). T(i, j) indicates the winning rate of team i when it is faced with team j. We guarantee that T(i, j) + T(j, i) = 1.0. All winning rates will retain two decimal places. An integer N (1 ≤ N ≤ 10000) is given next, which indicates the number of AI teams. The following line contains N integers which are the IDs (0-based) of the AI teams. The IDs can be duplicated.

Output

For each test case, please output the maximum winning probability if Josephina uses the best strategy in the game. For each answer, an absolute error not more than 1e-6 is acceptable.

Sample Input

40.50 0.50 0.20 0.300.50 0.50 0.90 0.400.80 0.10 0.50 0.600.70 0.60 0.40 0.5030 1 2

Sample Output

0.378000

Author: LIN, Yue
Contest: The 2013 ACM-ICPC Asia Changsha Regional Contest

是个比较简单的dp题目。
给你C(m,3)个人员相互之间的胜率,然后要你依次对战n个敌人,首先任选一种,然后战胜一个敌人后可以选择替换成敌人,也可以不换,问你最后最大的胜率是多少。

dp[i][j]代表是打败前i个队伍后且当前的队伍是j的最大胜率。。

dp[i][j] = max(dp[i][j],dp[i-1][j]*P[j][no[i]]); //代表不换
dp[i][no[i]] = max(dp[i][no[i]],dp[i-1][j]*P[j][no[i]]);//代表换战队


题目地址:Josephina and RPG

AC代码:
#include<iostream>#include<cstdio>using namespace std;double mp[202][202];double dp[10005][202];int a[10005];int cal(int x){    return x*(x-1)*(x-2)/6;}int main(){    int n,s,i,j;    double res;    int m;    while(~scanf("%d",&n))    {        s=cal(n);        for(i=0;i<s;i++)            for(j=0;j<s;j++)                scanf("%lf",&mp[i][j]);        //memset(dp,0,sizeof(dp));        for(i=0;i<s;i++)        {            dp[0][i]=1;            for(j=1;j<=m;j++)                dp[j][i]=0;        }        res=0;        scanf("%d",&m);        for(i=1;i<=m;i++)            scanf("%d",&a[i]);        for(i=1;i<=m;i++)        {            for(j=0;j<s;j++)            {                dp[i][j]=max(dp[i][j],dp[i-1][j]*mp[j][a[i]]);    //²»½»»»                dp[i][a[i]]=max(dp[i][a[i]],dp[i-1][j]*mp[j][a[i]]);  //½»»»            }        }        for(i=0;i<s;i++)            res=max(res,dp[m][i]);        printf("%.8f\n",res);    }    return 0;}



然后很快wzy上去敲,很快就A了这个dp题目,于是开始搞C题。
Collision

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

There's a round medal fixed on an ideal smooth table, Fancy is trying to throw some coins and make them slip towards the medal to collide. There's also a round range which shares exact the same center as the round medal, and radius of the medal is strictly less than radius of the round range. Since that the round medal is fixed and the coin is a piece of solid metal, we can assume that energy of the coin will not lose, the coin will collide and then moving as reflect.

Now assume that the center of the round medal and the round range is origin ( Namely (0, 0) ) and the coin's initial position is strictly outside the round range. Given radius of the medal Rm, radius of coin r, radius of the round range R, initial position (xy) and initial speed vector (vxvy) of the coin, please calculate the total time that any part of the coin is inside the round range.

Please note that the coin might not even touch the medal or slip through the round range.

Input

There will be several test cases. Each test case contains 7 integers RmRrxyvx and vy in one line. Here 1 ≤ Rm < R ≤ 2000, 1 ≤ r ≤ 1000, R + r < |(xy)| ≤ 20000, 1 ≤ |(vxvy)| ≤ 100.

Output

For each test case, please calculate the total time that any part of the coin is inside the round range. Please output the time in one line, an absolute error not more than 1e-3 is acceptable.

Sample Input

5 20 1 0 100 0 -15 20 1 30 15 -1 0

Sample Output

30.00029.394

Author: FAN, Yuzhe
Contest: The 2013 ACM-ICPC Asia Changsha Regional Contest


题目大意:给你一个运动的点cor,它的半径是r,起始坐标是x,y,运动方向是vx,vy,速度是v,然后以坐标原点为半径的一个medal半径为Rm,然后有一个区域半径为R,求这个cor在R中走的时间,碰到medal会反弹。。直接是数学物理题目,相切问题,不过有个情况需要特判,就是要先判断他的运动方向,而不仅仅是判断距离而已。这点当时坑了很久很久。。详见代码

题目地址:Collision

AC代码:
#include<iostream>#include<cmath>#include<cstdio>#include<cstring>using namespace std;const double eps = 1e-12;const double PI = acos(-1.0);double fun(double a){    if(a<0) return -a;    return a;}int main(){    double Rm,R,r,x0,y0,vx,vy,v;    while(~scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x0,&y0,&vx,&vy))    {        v=sqrt(vx*vx+vy*vy);        double dis = fun(y0*vx-x0*vy)/v;        if(dis-R-r>=eps) puts("0");        else if(dis-Rm-r>=eps)        {            if(x0*vx+y0*vy>=eps) puts("0");   //这个地方坑了很久,感谢那天志愿者的高钙牛奶            else            {                double s=2.0*sqrt((R+r)*(R+r)-dis*dis);                printf("%.9f\n",s/v);            }        }        else        {            if(x0*vx+y0*vy>=eps) puts("0");            /*else    //自己开始写的代码,后来可以简化成下面的            {                double a,b,c;                double angel=asin(dis/(Rm+r));                angel = PI - angel;                b=Rm+r,c=R+r;                a=(2.0*b*cos(angel)+sqrt(4.0*b*b*cos(angel)*cos(angel)-4.0*(b*b-c*c)))/2.0;                printf("%.9f\n",2.0*a/v);            }*/            else            {                double s = sqrt((R+r)*(R+r)-dis*dis)-sqrt((Rm+r)*(Rm+r)-dis*dis);                printf("%.9f\n",2*s/v);            }        }    }    return 0;}


最近生活节奏很不对劲。。需要好好调整!