zoukankan      html  css  js  c++  java
  • 2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming Contest(The 2019 Asia Yinchuan First Round Online Programming)

    Fight Against Monsters 

    It is my great honour to introduce myself to you here. My name is Aloysius Benjy Cobweb Dartagnan Egbert Felix Gaspar Humbert Ignatius Jayden Kasper Leroy Maximilian. As a storyteller, today I decide to tell you and others a story about the hero Huriyyah, and the monsters.

    Once upon a time, citizens in the city were suffering from nn powerful monsters. They ate small children who went out alone and even killed innocent persons. Before the hero appeared, the apprehension had overwhelmed the people for several decades.

    For the good of these unfortunate citizens, Huriyyah set off to the forest which was the main lair of monsters and fought with nn fierce and cruel monsters. The health point of the ii-th monster was HPiHPi, and its attack value was ATKiATKi.

    They fought in a cave through a turn-based battle. During each second, the hero Huriyyah was attacked by monsters at first, and the damage was the sum of attack values of all alive monsters. Then he selected a monster and attacked it. The monster would suffer the damage of kk (its health point would decrease by kk) which was the times of attacks it had been came under. That is to say, for each monster, the damage of the first time that Huriyyah attacked it was 11, and the damage of Huriyyah's second attack to this monster was 22, the third time to this monster was 33, and so on. If at some time, the health point of a monster was less than or equal to zero, it died. The hero won if all monsters were killed.

    Now, my smart audience, can you calculate the minimum amount of total damages our hero should suffer before he won the battle?

    Input

    The input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 103103.

    For each test case, the first line contains an integers n (1n105)n (1≤n≤105) which is the number of monsters.

    The ii-th line of the following nn lines contains two integers HPiHPi and ATKi (1HPi,ATKi105)ATKi (1≤HPi,ATKi≤105) which describe a monster.

    We guarantee that the sum of nn in all test cases is up to 106106.

    Output

    For each test case, output a line containing Case #x: y, where x is the test case number starting from 11, and y is the minimum amount of total damages the hero should suffer.

    Example
    input
    Copy
    2
    3
    1 1
    2 2
    3 3
    3
    3 1
    2 2
    1 3
    output
    Copy
    Case #1: 19
    Case #2: 14


    分析:要是受到的伤害最低,那么只要Kill小怪兽的顺序最优就可以啦,怎样最优呢?最优的影响因素是 kill 小怪兽的时间,而时间又受到小怪兽血量的影响
       所以呢,我们排序的时候就判断先kill A怪兽再kill B怪兽所受到的伤害高还是先kill B怪兽再kill A怪兽受到的伤害高
    PS:有队友提出优先队列做,这里提供一下思路,有兴趣的可以搞一下

     
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    using namespace std;
    #define pq priority_queue<int>
    #define pql priority_queue<ll>
    #define pqn priority_queue<node>
    #define v vector<int>
    #define vl vector<ll>
    #define lson rt<<1, l, m  
    #define rson rt<<1|1, m+1, r
    #define read(x) scanf("%d",&x)
    #define lread(x) scanf("%lld",&x);
    #define pt(x) printf("%d
    ",(x))
    #define yes printf("YES
    ");
    #define no printf("NO
    ");
    #define gcd __gcd
    #define cn cin>>
    #define ct cout<<
    #define ed <<endl;
    #define ok return 0 ;
    #define over cout<<endl;
    #define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++)
    #define input(k) for (int i = 1; i <= (int)(k); i++)  {cin>>a[i] ; }
    #define mem(s,t) memset(s,t,sizeof(s))
    #define re return 0;
    #define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define mod(x) ((x)%9973)
    #define test cout<<"     ++++++      "<<endl; 
    typedef long long ll;
    const int INT=1e6+5;
    const int maxn=10000+5;
    const int len = 1e5+5;
    
    typedef struct node
    {
        ll x,y,ankle,T;
    }node;
    //double getlen(node xx,node yy) { return sqrt( (xx.x-yy.x)*(xx.x-yy.x) +(xx.y-yy.y)*(xx.y-yy.y) ); } //计算两点间距离 
    node dp[len]; 
    int cmp(node a,node b)
    {
      /*  可以加可以不加
        if(b.y*a.T == a.y*b.T)
            return a.y>b.y;
      */
        return a.y*b.T > b.y*a.T ; 
    }
    int runtime(int num)
    {
        int k=1,t=0;
        while(num>0)
        {
            t++;
            num-=k;
            k++;
        }
        return t;
    }
    int main()
    {
        int t,n,k;
        cin>>t;
        for(int kk=1;kk<=t;kk++)
        {
            cin>>n;
            ll cnt=0,sum=0;
            rep(0,n-1)
            {
                cin>>dp[i].x>>dp[i].y;
                dp[i].T = runtime(dp[i].x) ;
                cnt+=dp[i].y;
            }
            sort(dp,dp+n,cmp);
            rep(0,n-1)
            {
                sum+=cnt*dp[i].T;
                cnt-=dp[i].y;
            }
            cout<<"Case #"<<kk<<": "<<sum<<endl;
        }
        ok;
    }
    View Code
     

    Caesar Cipher 

    In cryptography, a Caesar cipher, also known as the shift cipher, is one of the most straightforward and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions up (or down) the alphabet.

    For example, with the right shift of 1919, A would be replaced by T, B would be replaced by U, and so on. A full exhaustive list is as follows:

    • The plaintext: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z;
    • The ciphertext: T U V W X Y Z A B C D E F G H I J K L M N O P Q R S.

    Now you have a plaintext and its ciphertext encrypted by a Caesar Cipher. You also have another ciphertext encrypted by the same method and are asked to decrypt it.

    Input

    The input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 5050.

    For each test case, the first line contains two integers nn and m (1n,m50)m (1≤n,m≤50) indicating the length of the first two texts (a plaintext and its ciphertext) and the length of the third text which will be given. Each of the second line and the third line contains a string only with capital letters of length nn, indicating a given plaintext and its ciphertext respectively. The fourth line gives another ciphertext only with capital letters of length mm.

    We guarantee that the pair of given plaintext (in the second line) and ciphertext (in the third line) is unambiguous with a certain Caesar Cipher.

    Output

    For each test case, output a line containing Case #x: T, where x is the test case number starting from 11, and T is the plaintext of the ciphertext given in the fourth line.

    Example
    input
    Copy
    1
    7 7
    ACMICPC
    CEOKERE
    PKPIZKC
    output
    Copy
    Case #1: NINGXIA


    分析:分密文左移得到明文还是右移得到明文,密文-明文 > 0 左移减法 ,反之 右移加法。
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    using namespace std;
    #define pq priority_queue<int>
    #define pql priority_queue<ll>
    #define pqn priority_queue<node>
    #define v vector<int>
    #define vl vector<ll>
    #define lson rt<<1, l, m 
    #define rson rt<<1|1, m+1, r
    #define read(x) scanf("%d",&x)
    #define lread(x) scanf("%lld",&x);
    #define pt(x) printf("%d
    ",(x))
    #define yes printf("YES
    ");
    #define no printf("NO
    ");
    #define gcd __gcd
    #define cn cin>>
    #define ct cout<<
    #define ed <<endl;
    #define ok return 0 ;
    #define over cout<<endl;
    #define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++)
    #define input(k) for (int i = 1; i <= (int)(k); i++) {cin>>a[i] ; }
    #define mem(s,t) memset(s,t,sizeof(s))
    #define re return 0;
    #define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define mod(x) ((x)%9973)
    #define test cout<<" ++++++ "<<endl; 
    typedef long long ll;
    const int INT=1e6+5;
    const int maxn=10000+5;
    const int len = 1e5+5;
    
    
    int main()
    {
        int t,n,k;
        cin>>t;
        string s="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
        for(int kk=1;kk<=t;kk++)
        {
            string str,sub,ch;
            cin>>n>>k;
            cin>>str>>sub>>ch;
            n=sub[0]-str[0];
            cout<<"Case #"<<kk<<": "<<endl;
            if(n>=0)
            {
                rep(0,ch.size()-1)
                    ct s[ 26+ch[i]-'A'-n ];
            }
            else
            {
                n=-n;
                rep(0,ch.size()-1)
                    ct s[ ch[i]-'A'+n ];          
            }
        over;
        }
        ok;
    }
    View Code

    Rolling The Polygon 

    Bahiyyah has a convex polygon with nn vertices P0,P1,,Pn1P0,P1,⋯,Pn−1 in the counterclockwise order. Two vertices with consecutive indexes are adjacent, and besides, P0P0 and Pn1Pn−1 are adjacent. She also assigns a point QQ inside the polygon which may appear on the border.

    Now, Bahiyyah decides to roll the polygon along a straight line and calculate the length of the trajectory (or track) of point QQ.

    To help clarify, we suppose Pn=P0,Pn+1=P1Pn=P0,Pn+1=P1 and assume the edge between P0P0 and P1P1 is lying on the line at first. At that point when the edge between Pi1Pi−1 and PiPi lies on the line, Bahiyyah rolls the polygon forward rotating the polygon along the vertex PiPi until the next edge (which is between PiPi and Pi+1Pi+1) meets the line. She will stop the rolling when the edge between PnPn and Pn+1Pn+1 (which is same as the edge between P0P0 and P1P1) meets the line again.

    Input

    The input contains several test cases, and the first line is a positive integer TT indicating the number of test cases which is up to 5050.

    For each test case, the first line contains an integer n (3n50)n (3≤n≤50) indicating the number of vertices of the given convex polygon. Following nn lines describe vertices of the polygon in the counterclockwise order. The ii-th line of them contains two integers xi1xi−1 and yi1yi−1, which are the coordinates of point Pi1Pi−1. The last line contains two integers xQxQ and yQyQ, which are the coordinates of point QQ.

    We guarantee that all coordinates are in the range of 103−103 to 103103, and point QQ is located inside the polygon or lies on its border.

    Output

    For each test case, output a line containing Case #x: y, where x is the test case number starting from 11, and y is the length of the trajectory of the point QQ rounded to 33 places. We guarantee that 44-th place after the decimal point in the precise answer would not be 44 or 55.

    input
    Copy
    4
    4
    0 0
    2 0
    2 2
    0 2
    1 1
    3
    0 0
    2 1
    1 2
    1 1
    5
    0 0
    1 0
    2 2
    1 3
    -1 2
    0 0
    6
    0 0
    3 0
    4 1
    2 2
    1 2
    -1 1
    1 0
    output
    Copy
    Case #1: 8.886
    Case #2: 7.318
    Case #3: 12.102
    Case #4: 14.537

    分析:暴力附加两个数据,dp[0] = dp[n] , dp[n+1]=dp[1],按余弦定理计算就能AC。
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    using namespace std;
    #define pq priority_queue<int>
    #define pql priority_queue<ll>
    #define pqn priority_queue<node>
    #define v vector<int>
    #define vl vector<ll>
    #define lson rt<<1, l, m  
    #define rson rt<<1|1, m+1, r
    #define read(x) scanf("%d",&x)
    #define lread(x) scanf("%lld",&x);
    #define pt(x) printf("%d
    ",(x))
    #define yes printf("YES
    ");
    #define no printf("NO
    ");
    #define gcd __gcd
    #define cn cin>>
    #define ct cout<<
    #define ed <<endl;
    #define ok return 0 ;
    #define over cout<<endl;
    #define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++)
    #define input(k) for (int i = 1; i <= (int)(k); i++)  {cin>>a[i] ; }
    #define mem(s,t) memset(s,t,sizeof(s))
    #define re return 0;
    #define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define mod(x) ((x)%9973)
    #define test cout<<"     ++++++      "<<endl; 
    typedef long long ll;
    const int INT=1e6+5;
    const int maxn=10000+5;
    const int len = 1e5+5;
    
    typedef struct node
    {
        int x,y,ankle,T;
    }node;
    node dp[len]; 
    double getlen(node xx,node yy) { return ( (xx.x-yy.x)*(xx.x-yy.x) +(xx.y-yy.y)*(xx.y-yy.y) ); } //计算两点间距离 
    int main()
    {
        TLE;
        int t,n,k;
        cin>>t;
    
        for(int kk=1;kk<=t;kk++)
        {
            double sum=0;
            cin>>n;
            rep(1,n)
                cin>>dp[i].x>>dp[i].y;
            dp[0].x=dp[n].x;      dp[0].y=dp[n].y;
            dp[n+1].x=dp[1].x;    dp[n+1].y=dp[1].y;
            cin>>dp[n+2].x>>dp[n+2].y;
            rep(1,n)
            {
                double dis = getlen(dp[i],dp[n+2]);
                double d1 = getlen(dp[i],dp[i+1]);
                double d2 = getlen(dp[i],dp[i-1]); 
                double d3 = getlen(dp[i+1],dp[i-1]); 
                sum+= sqrt( dis )*abs(  acos(-1.0) - acos( ( d1+d2-d3)/(2*sqrt(d1)*sqrt(d2)) ) );
            }
            printf("Case #%d: %.3lf
    ",kk,sum);
        }
        ok;
    }



    分析:数学签到题,( 可以重点关注一下 小技巧 (i+1)%n 和 (i-1)%n  )


    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    using namespace std;
    #define pq priority_queue<int>
    #define pql priority_queue<ll>
    #define pqn priority_queue<node>
    #define v vector<int>
    #define vl vector<ll>
    #define lson rt<<1, l, m  
    #define rson rt<<1|1, m+1, r
    #define read(x) scanf("%d",&x)
    #define lread(x) scanf("%lld",&x);
    #define pt(x) printf("%d
    ",(x))
    #define yes printf("YES
    ");
    #define no printf("NO
    ");
    #define gcd __gcd
    #define cn cin>>
    #define ct cout<<
    #define ed <<endl;
    #define ok return 0 ;
    #define over cout<<endl;
    #define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++)
    #define input(k) for (int i = 1; i <= (int)(k); i++)  {cin>>a[i] ; }
    #define mem(s,t) memset(s,t,sizeof(s))
    #define re return 0;
    #define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define mod(x) ((x)%9973)
    #define test cout<<"     ++++++      "<<endl; 
    typedef long long ll;
    const int INT=1e6+5;
    const int maxn=10000+5;
    const int len = 1e5+5;
    
    typedef struct node
    {
        int x,y,ankle,T;
    }node;
    node dp[len]; 
    double getlen(node xx,node yy) { return ( (xx.x-yy.x)*(xx.x-yy.x) +(xx.y-yy.y)*(xx.y-yy.y) ); } //计算两点间距离平方 
    int main()
    {
        TLE;
        int t,n,k;
        cin>>t;
        for(int kk=1;kk<=t;kk++)
        {
            double sum=0;
            cin>>n;
            rep(0,n-1)
                cin>>dp[i].x>>dp[i].y;
            cin>>dp[n+2].x>>dp[n+2].y;
            rep(0,n-1)
            {
                double dis = getlen(dp[i],dp[n+2]);
                double d1 = getlen(dp[i],dp[(i+1)%n]);
                double d2 = getlen(dp[i],dp[(i-1+n)%n]); 
                double d3 = getlen(dp[(i+1)%n],dp[(i-1+n)%n]);     
                sum+= sqrt( dis )*abs(  acos(-1.0) - acos( ( d1+d2-d3)/(2*sqrt(d1)*sqrt(d2)) ) );        
            }
            printf("Case #%d: %.3lf
    ",kk,sum);
        }
        ok;
    }
    所遇皆星河
  • 相关阅读:
    java中继承和多态的理解
    汽车租赁系统
    s2第六章继承和多态
    第三章泛型集合ArrayList 和Hashtable
    第二章项目总结
    s2第二章深入c#类型
    .NET平台
    航班查询系统
    java初始重点语法
    JDBC
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11441375.html
Copyright © 2011-2022 走看看