• Codeforces Round #467 (Div. 2)


    A.Olympiad

      题意:有n个人,现在给他们发证。如果给一个成绩为i的人发证,所有成绩不低于他的人都要发证;成绩为0的不能发证。问方案数。

      思路:答案为成绩不为0的不同的个数。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<set>
     4 using namespace std;
     5 int main()
     6 {
     7     int n;
     8     scanf("%d", &n);
     9     set<int>s;
    10     for (int i = 1; i <= n; i++)
    11     {
    12         int t;
    13         scanf("%d", &t);
    14         if(t!=0) s.insert(t);
    15     }
    16     printf("%d
    ", s.size());
    17 
    18     return 0;
    19 }
    View Code

     B. Vile Grasshoppers

      题意:找2~y之间不被2~p任意数除的最大数。

      思路:从y到p+1,找不被1~mIn(p,sqrt(i)+1)的数

     1 #include<iostream>
     2 #include<cmath>
     3 #include<algorithm>
     4 using namespace std;
     5 int p, y;
     6 int ok(int tmp)
     7 {
     8     for (int i = 2; i <= min(p,(int)(sqrt(tmp))+1); i++)
     9     {
    10         if (tmp%i == 0) return false;
    11     }
    12     return true;
    13 }
    14 int solve()
    15 {
    16     for (int i = y; i > p; i--)
    17     {
    18         if (ok(i)) return i;
    19     }
    20     return -1;
    21 }
    22 int main()
    23 {
    24     scanf("%d%d", &p, &y);
    25     printf("%d
    ", solve());
    26     return 0 ;
    27 }
    View Code

     C. Save Energy!

      题意:电饭锅每过k分钟自动保温,人每过d分钟检查电饭锅是否在没烧熟就保温,是则重新加热。食物如果一直加热需要t分钟,如果一直保温需要2*t分钟。问当食物刚煮熟的时间?

      思路:找到一个循环节(大于等于k的最小的d的倍数)。然后看减去所有循环节剩下的时间。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 using namespace std;
     5 int main()
     6 {
     7     long long k, d, t;
     8     scanf("%I64d%I64d%I64d", &k, &d, &t);
     9     if (k%d == 0) printf("%I64d
    ", t);
    10     else
    11     {
    12         double tot_time = 0,p=0;
    13         long long tmp = d*((long long)(k / d) + 1);//循环节
    14         long long count = 2.0*t/(tmp+k);//1.0/(1.0*k/t+1.0*(tmp-k)/(2*t)),循环节数目
    15         tot_time += count * tmp;
    16         if (count*(tmp+k) + k*2>2*t)//count*(1.0*k / t + 1.0*(tmp - k) / (2 * t)) + k/t>1
    17         {
    18             tot_time += 1.0*(2ll*t-count*1ll*(tmp+k))/2ll;// (1.0-count*(1.0*k / t + 1.0*(tmp - k) / (2 * t)))/(1/t)
    19         }
    20         else
    21         {
    22             tot_time += k;
    23             tot_time += 2ll * t - count * 1ll * (tmp + k) - k * 2;// (1.0-count*(1.0*k / t + 1.0*(tmp - k) / (2 * t))-k/t)/(1/2t)
    24         }
    25         printf("%.12lf
    ", tot_time);
    26     }
    27     return 0;
    28 }
    View Code
  • 相关阅读:
    状态模式
    迭代器模式和组合模式
    模板方法模式
    适配器模式和外观模式
    principle06
    principle05
    命令模式
    单例模式
    工厂模式
    day38(表相关内容)
  • 原文地址:https://www.cnblogs.com/ivan-count/p/8573499.html
Copyright © 2020-2023  润新知