• 2018 计蒜之道 初赛 第一场


    A-百度无人车

    题解:典型的二分

     1 #pragma warning(disable:4996)
     2 #include<map>
     3 #include<queue>
     4 #include<string>
     5 #include<cstdio>
     6 #include<cstring>
     7 #include<iostream>
     8 #include<algorithm>
     9 #define ll long long 
    10 using namespace std;
    11 
    12 const int maxn = 20005;
    13 
    14 ll s;
    15 int n, p;
    16 int a[maxn];
    17 
    18 bool check(int mid) {
    19     int pos = lower_bound(a + 1, a + n + 1, mid) - a;
    20     int ans = 0;
    21     for (int i = pos; i <= n; i++) ans += (a[i] - mid);
    22     if (ans > s / p) return false;
    23     return true;
    24 }
    25 
    26 int Solve() {
    27     int l = 1, r = a[n];
    28     for (int i = 1; i <= 30; i++) {
    29         int mid = (l + r) >> 1;
    30         if (check(mid)) r = mid;
    31         else l = mid + 1;
    32     }
    33     return l;
    34 }
    35 
    36 int main()
    37 {
    38     while (scanf("%d", &n) != EOF) {
    39         for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    40         sort(a + 1, a + n + 1);
    41         scanf("%d%lld", &p, &s);
    42         printf("%d
    ", Solve());
    43     }
    44     return 0;
    45 }

    B-百度科学家

    题解:数据比较小的时候建图,跑DFS统计总的污染值即可。

    感受:题意不明!!!!!书替换后不会对以前的结果造成影响。所以~~要n何用。

     1 #pragma warning(disable:4996)
     2 #include<vector>
     3 #include<string>
     4 #include<cstdio>
     5 #include<cstring>
     6 #include<iostream>
     7 #include<algorithm>
     8 #define ll long long 
     9 using namespace std;
    10 
    11 const ll INF = 1000000000000000;
    12 
    13 int n, m;
    14 int p[30], pos[30];
    15 
    16 vector<int> book[30];
    17 
    18 bool use[30];
    19 
    20 ll dp[30];
    21 
    22 void DFS(int u) {
    23     use[u] = 1;
    24     dp[u] = p[u];
    25     for (int i = 0; i < book[u].size(); i++) {
    26         int v = book[u][i];
    27         if (!use[v]) {
    28             DFS(v);
    29             dp[u] += dp[v];
    30         }
    31     }
    32 }
    33 
    34 int main()
    35 {
    36     while (cin >> n) {
    37         for (int i = 1; i <= n; i++) pos[i] = i;
    38         for (int i = 1; i <= n; i++) cin >> p[i];
    39 
    40         cin >> m;
    41         int k = n;
    42         for (int i = 1; i <= m; i++) {
    43             int op;
    44             cin >> op;
    45             if (op == 0) {
    46                 int x, v;
    47                 cin >> x >> v;
    48                 pos[x] = (++k);
    49                 p[k] = v;
    50             }
    51             else {
    52                 int x, l, r;
    53                 cin >> x >> l >> r;
    54                 for (int i = l; i <= r; i++) book[pos[x]].push_back(pos[i]);
    55             }
    56         }
    57 
    58         ll ans = INF;
    59         for (int i = 1; i <= k; i++) {
    60             memset(use, 0, sizeof(use));
    61             memset(dp, 0, sizeof(dp));
    62             DFS(i);
    63             ans = min(ans, dp[i]);
    64         }
    65         cout << ans << endl;
    66 
    67         for (int i = 1; i <= k; i++) book[i].clear();
    68     }
    69     return 0;
    70 }
  • 相关阅读:
    flask的Request对象
    Spinner实现列表下拉功能
    ListView用法
    DatePickerDialog和TimePickerDialog(基于对话框显示时间和日期)
    DataPicker以及TimePicker显示时间和日期(屏幕上显示)
    Floyd-Warshall算法(最短路)
    Bellman-Ford算法(最短路)
    前向星
    css3变形与动画
    CSS3背景 background-size
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/9031492.html
Copyright © 2020-2023  润新知