zoukankan      html  css  js  c++  java
  • 2020.10.23 19级training 补题报告

    CF758C Unfair Poll

     1.题意

      教室里有恰好n行m列学生,老师提问的顺序是第一行、第二行···第n行、第n-1行···第二行,往复循环,每一行提问的顺序都是从第一列到第m列。问被提问最多的学生被提问了多少次,被提问最少的学生被提问了多少次,指定的某个学生被提问了多少次。

     2.题解

      用二维数组存学生被提问的次数,行数:1、2、3、····、n-1、n、n-1、n-2、···、2为一个循环节,模拟即可,另外需要考虑只有一行的情况。

     3.代码

     1 //https://blog.csdn.net/lyg_air/article/details/77569620?utm_medium=distribute.pc_relevant_t0.none-task-blog-OPENSEARCH-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-OPENSEARCH-1.channel_param
     2 #include<bits/stdc++.h>
     3 #define ll long long
     4 using namespace std;
     5 const int maxn = 105;
     6 const ll INF = 1e18 + 5;
     7 ll a[maxn][maxn];
     8 int main() {
     9     ll n, m, k, x, y;
    10     scanf("%lld%lld%lld%lld%lld", &n, &m, &k, &x, &y);
    11     int sum = 0;
    12     for(int i = 1; i <= n; i++) {
    13         sum += m;
    14     }
    15     for(int i = n - 1; i >= 2; i--) {
    16         sum += m;
    17     }
    18     
    19     ll p = k / sum;
    20     for(int i = 2; i <= n - 1; i++) {
    21         for(int j = 1; j <= m; j++) {
    22             a[i][j] += 2 * p;
    23         }
    24     }
    25     for(int j = 1; j <= m; j++) {
    26         a[1][j] += p;
    27     }
    28     if(n != 1) {
    29         for(int j = 1; j <= m; j++) {
    30             a[n][j] += p;
    31         }
    32     }
    33     
    34     k -= sum * p;
    35     if(k) {
    36         for(int i = 1; i <= n; i++){
    37             for(int j = 1; j <= m; j++){
    38                 a[i][j] += 1;
    39                 k--;
    40                 if(!k) {
    41                     break;
    42                 }
    43             }
    44             if(!k) {
    45                 break;
    46             }
    47         }
    48     }
    49     if(k) {
    50         for(int i = n - 1; i >= 2; i--) {
    51             for(int j = 1; j <= m; j++) {
    52                 a[i][j] += 1;
    53                 k--;
    54                 if(!k) {
    55                        break;    
    56                 }
    57             }
    58             if(!k) {
    59                 break;
    60             }
    61         }
    62     }
    63     
    64     ll ans1 = 0, ans2 = INF;
    65     for(int i = 1; i <= n; i++) {
    66         for(int j = 1; j <= m; j++) {
    67             ans1 = max(ans1, a[i][j]);
    68             ans2 = min(ans2, a[i][j]);
    69         }
    70     }
    71     printf("%lld %lld %lld
    ", ans1, ans2, a[x][y]);
    72   
    73     return 0;
    74 }
    View Code

    CF864C Bus

     1.题意

       一辆汽车在x轴上从x=0处到x=a处往返k次旅行(从0->a算一次,从a->0算一次)。在开始时汽车油箱有b升油,汽车每行驶一单位距离消耗一升油,在x=f处有加油站,每次经过加油站都可以加满油或者不加油。问完成这k次旅行最少需要加油多少次,如果不能完成输出-1。

     2.题解

      模拟。

     3.代码

     1 #include<bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 int main() {
     5     int a, b, f, k; 
     6     scanf("%d%d%d%d", &a, &b, &f, &k);
     7     int l = f;
     8     int r = a - f;
     9     int now = b - f; 
    10     
    11     if(now < 0) {
    12         cout << "-1" << endl;
    13         return 0;
    14     }
    15     int ans = 0;
    16     for(int i = 1; i <= k - 1; i++) {  
    17         if(i % 2 == 1) {
    18             if(now >= 2 * r) {
    19                 now -= 2 * r;    
    20             } else {
    21                 now = b - 2 * r;
    22                 ans++;
    23                 if(now < 0) {
    24                     cout << "-1" << endl;
    25                     return 0;
    26                 }
    27             }
    28         } else {
    29             if(now >= 2 * l) {
    30                 now -= 2 * l;
    31             } else {
    32                 now = b - 2 * l;
    33                 ans++;
    34                 if(now < 0) {
    35                     cout << "-1" << endl;
    36                     return 0;
    37                 }
    38             }
    39         }    
    40     }
    41     if(k % 2 == 1) {
    42         if(now < r) {
    43             now = b - r;
    44             ans++;
    45             if(now < 0) {
    46                 cout << "-1" << endl;
    47                 return 0;
    48             }
    49         }
    50     } else {
    51         if(now < l) {
    52             now = b - l;
    53             ans++;
    54             if(now < 0) {
    55                 cout << "-1" << endl;
    56                 return 0;
    57             }
    58         }
    59     }
    60     cout << ans << endl; 
    61     
    62     return 0;
    63 }
    View Code
  • 相关阅读:
    mysql修改数据表名
    HDU 5742 It's All In The Mind (贪心)
    HDU 5752 Sqrt Bo (数论)
    HDU 5753 Permutation Bo (推导 or 打表找规律)
    HDU 5762 Teacher Bo (暴力)
    HDU 5754 Life Winner Bo (博弈)
    CodeForces 455C Civilization (并查集+树的直径)
    CodeForces 455B A Lot of Games (博弈论)
    CodeForces 455A Boredom (DP)
    HDU 4861 Couple doubi (数论 or 打表找规律)
  • 原文地址:https://www.cnblogs.com/lvguapi/p/13901312.html
Copyright © 2011-2022 走看看