zoukankan      html  css  js  c++  java
  • HDU重现赛之2019CCPC-江西省赛

    本人蒟蒻,5个小时过了5道,看到好几个大佬AK,%%%%%%%

    http://acm.hdu.edu.cn/contests/contest_show.php?cid=868

    先放大佬的题解(不是我写的。。同学给的),能理解多少就靠你们自己了,还是希望大家能从大佬的题解中有所收获

    口胡题解:

    A. Co-Tree:由目标函数提到的两两距离和,可想到,在树上找个点,使得它到其它点距离和最小。

    B. Math:考虑每秒开始时 “avin 拿着 Robot 在 i 点” 的状态 到 “Avin 拿着 Robot 在 i+1 点” 状态,需要时间 的期望?⼀一个状态自己转移到自己怎么办?

    C. Trap:在互质这个限制条件,容斥!那么考虑没有互质的限制怎么做?枚举两条边,第三条边方案数怎么 快速统计?

    D. Wave:枚举两种不同的数,复杂度多少?

    E. Packing:我们需要决策,能 DP 吗?能贪心吗?按什么优先级来决定发哪个缓冲区的货呢?

    F. String:乘法原理。

    G. Traffic:哪些等待时间不合法?

    H. Rng:for,for 枚举右端点可以做啊!观察两个 for 的做法,变成一个 for 就 win 了。

    I. Buget:最低位决定答案。

    J. Worker:按比例分配。

    K. Class:解方程。

     详细题解:

    有些符号粘不出来,放截图吧,望见谅


    有兴趣可以看看我过的题目(太蒻了,有点不好意思)

     下面是题目:


    1011 Class

    Problem Description

    Avin has two integers a, b (1 ≤ a, b ≤ 1, 000).
    Given x = a + b and y = a - b, can you calculate a*b?

    Input

    The first line contains two integers x, y.

    Output

    Print the result of a*b.

    Sample Input

    4 2

    Sample Output

     3

    签到题,直接粘代码

     1 #include <stdio.h>
     2 #include <algorithm>
     3 
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int a,b,x,y;
     9     scanf("%d %d",&x,&y);
    10     a=(x+y)/2;
    11     b=(x-y)/2;
    12     printf("%d
    ",a*b);
    13     return 0;
    14 }

    1006 String

    Problem Description

    Avin has a string. He would like to uniform-randomly select four characters (selecting the same character is allowed) from it. You are asked to calculate the probability of the four characters being ”avin” in order.

    Input

    The first line contains n (1 ≤ n ≤ 100), the length of the string. The second line contains the string. To simplify the problem, the characters of the string are from ’a’, ’v’, ’i’, ’n’.

    Output

    Print the reduced fraction (the greatest common divisor of the numerator and denominator is 1), representing the probability. If the answer is 0, you should output "0/1".

    Sample Input

    4
    avin
    4
    aaaa

    Sample Output

    1/256
    0/1

     暴力过的,十分暴力

     1 #include <stdio.h>
     2 #include <algorithm>
     3 
     4 using namespace std;
     5 
     6 int gcd(int a,int b)
     7 {
     8     if(b==0)
     9         return a;
    10     else return gcd(b,a%b);
    11 }
    12 
    13 int main()
    14 {
    15     int n;
    16     while(~scanf("%d",&n))
    17     {
    18         getchar();
    19         char str[101];
    20         for(int i=1;i<=n;i++)
    21         {
    22             str[i]=getchar();
    23         }
    24         int tot=0;
    25         int sum=0;
    26         for(int i=1;i<=n;i++)
    27         {
    28             for(int j=1;j<=n;j++)
    29             {
    30                 for(int g=1;g<=n;g++)
    31                 {
    32                     for(int k=1;k<=n;k++)
    33                     {
    34                         tot++;
    35 //                        if(i<j&&j<g&&g<k)   //第一次wa的点,理解错题意了
    36 //                        {
    37                             if(str[i]=='a'&&str[j]=='v'&&str[g]=='i'&&str[k]=='n')
    38                                 sum++;
    39 //                        }
    40                     }
    41                 }
    42             }
    43         }
    44         if(sum!=0)
    45         {
    46             int t=gcd(sum,tot);
    47 //            printf("sum=%d tot=%d t=%d
    ",sum,tot,t);
    48             printf("%d/%d
    ",sum/t,tot/t);
    49         }
    50         else
    51             printf("0/1
    ");
    52     }
    53     return 0;
    54 }

    1009 Budget

    Problem Description

    Avin’s company has many ongoing projects with different budgets. His company records the budgets using numbers rounded to 3 digits after the decimal place. However, the company is updating the system and all budgets will be rounded to 2 digits after the decimal place. For example, 1.004 will be rounded down
    to 1.00 while 1.995 will be rounded up to 2.00. Avin wants to know the difference of the total budget caused by the update.

    Input

    The first line contains an integer n (1 ≤ n ≤ 1, 000). The second line contains n decimals, and the i-th decimal ai (0 ≤ ai ≤ 1e18) represents the budget of the i -th project. All decimals are rounded to 3 digits.

    Output

    Print the difference rounded to 3 digits..

    Sample Input

    1
    1.001
    1
    0.999
    2
    1.001 0.999

    Sample Output

    -0.001
    0.001
    0.000

    不管输入是不是三位小数了,我当做不是来写的,中间写的时候又有了新的想法,稍微改变了思路,所以29~35行有点乱,懒得改了,能过就直接交了

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int n;
    10     while(~scanf("%d",&n))
    11     {
    12         char str[101];
    13         double sum=0;
    14         for(int i=0;i<n;i++)
    15         {
    16             double tem=0;
    17             scanf("%s",str);
    18             int len=strlen(str);
    19             int flag=0;
    20             int t=1000;
    21             for(int i=0;i<len;i++)
    22             {
    23                 if(flag)
    24                 {
    25                     tem+=(str[i]-'0')*1.0/t;
    26                     t*=10;
    27                     continue;
    28                 }
    29                 if(str[i]!='.')
    30                 {
    31                     str[i]='0';
    32                 }
    33                 else
    34                 {
    35                     flag=1;
    36                     
    37                     if(str[i+1])
    38                         str[i+1]='0';
    39                     else
    40                         break;
    41                     if(str[i+2])
    42                         str[i+2]='0';
    43                     else break;
    44                     i+=2;
    45                 }
    46             }
    47             if(tem<0.005)
    48                 sum-=tem;
    49             else
    50                 sum+=0.01-tem;
    51         }
    52         if(sum<0)
    53         {
    54             printf("-");
    55             sum=-sum;
    56         }
    57         printf("%.3lf
    ",sum);
    58     }
    59     return 0;
    60 }

    1010 Worker

    Problem Description

    Avin meets a rich customer today. He will earn 1 million dollars if he can solve a hard problem. There are n warehouses and m workers. Any worker in the i-th warehouse can handle ai orders per day. The customer wonders whether there exists one worker assignment method satisfying that every warehouse handles the same number of orders every day. Note that each worker should be assigned to exactly one warehouse and no worker is lazy when working.

    Input

    The first line contains two integers n (1 ≤ n ≤ 1, 000), m (1 ≤ m ≤ 1018). The second line contains n integers. The i-th integer ai (1 ≤ ai ≤ 10) represents one worker in the i-th warehouse can handle ai orders per day.

    Output

    If there is a feasible assignment method, print "Yes" in the first line. Then, in the second line, print n integers with the i-th integer representing the number of workers assigned to the i-th warehouse.
    Otherwise, print "No" in one line. If there are multiple solutions, any solution is accepted.

    Sample Input

    2 6
    1 2
    2 5
    1 2

    Sample Output

    Yes
    4 2
    No

     根据比例分配的问题,这个long long就很烦,一直在卡我,注意1018是1018,十分无语

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 
     5 using namespace std;
     6 typedef long long  LL;
     7 LL n,m;
     8 
     9 int gcd(LL a,LL b)
    10 {
    11     if(b==0) return a;
    12     else return gcd(b,a%b);
    13 }
    14 
    15 int lcm(LL a,LL b)
    16 {
    17     return (a/gcd(a,b) )*b;
    18 }
    19 
    20 int main()
    21 {    
    22     while(~scanf("%lld %lld",&n,&m))
    23     {
    24         LL a[1001];
    25         LL t[1001];
    26         LL w[1001];
    27         LL z=1;
    28         for(LL i=1;i<=n;i++)
    29         {
    30             scanf("%lld",&a[i]);
    31             z=lcm(max(z,a[i]),min(z,a[i]));
    32         }
    33 //        printf("z=%lld
    ",z);
    34         LL sum=0;
    35         for(LL i=1;i<=n;i++)
    36         {
    37             t[i]=z/a[i];
    38             sum+=t[i];
    39 //            printf("t[%d]=%d,sum=%d
    ",i,t[i],sum);
    40         }
    41         if(m%sum!=0)
    42         {
    43             printf("No
    ");
    44             continue;
    45         }
    46         printf("Yes
    ");
    47         LL g=m/sum;
    48 //        printf("g=%d
    ",g);
    49         for(LL i=1;i<=n;i++)
    50         {
    51             if(i==1)
    52                 printf("%lld",t[i]*g);
    53             else
    54                 printf(" %lld",t[i]*g);
    55         }
    56         printf("
    ");
    57     }
    58     return 0;
    59 }

    1007 Traffic

    Problem Description

    Avin is observing the cars at a crossroads. He finds that there are n cars running in the east-west direction with the i-th car passing the intersection at time ai . There are another m cars running in the north-south direction with the i-th car passing the intersection at time bi . If two cars passing the intersections at the same time, a traffic crash occurs. In order to achieve world peace and harmony, all the cars running in the north-south direction wait the same amount of integral time so that no two cars bump. You are asked the minimum waiting time.

    Input

    The first line contains two integers n and m (1 ≤ n, m ≤ 1, 000). The second line contains n distinct integers ai (1 ≤ ai ≤ 1, 000). The third line contains m distinct integers bi (1 ≤ bi ≤ 1, 000).

    Output

    Print a non-negative integer denoting the minimum waiting time.

    Sample Input

    1 1
    1
    1
    1 2
    2
    1 3

    Sample Output

    1
    0

     这个刚开始有点不理解车是怎样个等法,后来见好多人都交了,我就按照我自己的理解去写了,直接AC了,真好,就是感觉这种等法太反人类了

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 
     5 using namespace std;
     6 int n,m;
     7 
     8 
     9 int main()
    10 {
    11     while(~scanf("%d %d",&n,&m))
    12     {
    13         int a[3001]={0};
    14         int b[3001]={0};
    15         for(int i=0;i<n;i++)
    16         {
    17             int t;
    18             scanf("%d",&t);
    19             a[t]=1;
    20         }
    21         for(int i=0;i<m;i++)
    22         {
    23             int t;
    24             scanf("%d",&t);
    25             b[t]=1;
    26         }
    27         int p=0;
    28         while(1)
    29         {
    30             int flag=1;
    31             for(int i=1;i<3001;i++)
    32             {
    33                 if(b[i])
    34                 {
    35                     if(a[i+p])
    36                     {
    37                         flag=0;
    38                         break;
    39                     }
    40                 }
    41             }
    42             if(flag)
    43             {
    44                 break;
    45             }
    46             p++;
    47         }
    48         printf("%d
    ",p);
    49     }
    50     return 0;
    51 }

    船新版本

     1 int main()
     2 {
     3     while(~scanf("%d %d",&n,&m))
     4     {
     5         int a[3001]={0};
     6         int b[3001]={0};
     7         for(int i=0;i<n;i++)
     8         {
     9             int t;
    10             scanf("%d",&t);
    11             a[t]=1;
    12         }
    13         for(int i=0;i<m;i++)
    14         {
    15             scanf("%d",&b[i]);
    16         }
    17         int p=0;
    18         for(int i=0;i<m;i++)
    19         {
    20             
    21             if(a[b[i]+p])
    22             {
    23                 p++;
    24                 i=-1;
    25             }
    26         }    
    27         printf("%d
    ",p);
    28     }
    29     return 0;
    30 }

    除了AC的5题,我和队友还尝试了Wave和Rng。Wave懂题意了,但不会做,Rng很简单,有快200人过了没读懂题,只能猜、猜、猜、菜、菜、菜。。。。

    最后说一句RNGNB!!!

     
     
     
  • 相关阅读:
    六、MySQL系列之数据备份(六)
    一:MySQL系列之基本介绍(一)
    第十一篇:面向对象之属性方法
    第十篇:面向对象系列之三大特性(二)
    Python开发之路:目录篇
    Linux基础知识(二)
    前端CSS规范整理
    如何使用BMap.Point传递变量、存储数据?
    百度地图API应用之获取用户的具体位置
    Bootstrap入门一:Hello Bootstrap
  • 原文地址:https://www.cnblogs.com/jiamian/p/11222092.html
Copyright © 2011-2022 走看看