正睿20秋季普转提day6

估分:100+100+14+12=226

实际:100+100+14+12=226

T1:

  两人之差为偶数时就往中间走就行,最后一定能碰上

  两人之差为奇数时先往一个方向走知道有一人不能再走,然后另一人再走一步两人的差就为偶数了,然后就按上面的方法做

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 typedef long long LL;
 8 
 9 inline LL read()
10 {
11     LL x = 0, f = 0;
12     char ch = getchar();
13     while (!isdigit(ch)) f = ch == '-', ch = getchar();
14     while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
15     return f ? -x : x;
16 }
17 
18 int main()
19 {
20     LL n = read(), l = read(), r = read();
21     if ((r - l) % 2 == 0) printf("%lld", (r - l) / 2);
22     else printf("%lld", min(l + (r - l) / 2, n - r + 1 + (r - l) / 2));
23 }
View Code

T2:

  预处理出p[i][sta],表示选择sta这个状态的品牌下价值小于pri[i]的物品有多少个,每次询问就二分查找就行,因为只有5种品牌,所以最多只有31种情况,完全跑得起

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<map>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 inline int read()
 9 {
10     int x = 0, f = 0;
11     char ch = getchar();
12     while (!isdigit(ch)) f = ch == '-', ch = getchar();
13     while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
14     return f ? -x : x;
15 }
16 
17 const int N = 100010;
18 
19 int n;
20 int num[35], pri[N][35];
21 
22 struct Node
23 {
24     int bra, p, id;
25     Node() {}
26 }s[N];
27 
28 bool cmp(Node a, Node b) { return a.p < b.p; }
29 
30 inline bool check(int x, int sta, int k) { return pri[x][sta] >= k; }
31 
32 int main()
33 {
34     n = read();
35     for (int i = 1; i <= n; i++) s[i].bra = read();
36     for (int i = 1; i <= n; i++) s[i].p = read(), s[i].id = i;
37     sort(s + 1, s + 1 + n, cmp);
38 
39     for (int i = 1; i <= n; i++)
40     {
41         for (int sta = 0; sta < (1 << 5); sta++)
42         {
43             if ((sta >> (s[i].bra - 1)) & 1) num[sta]++;
44             pri[i][sta] = num[sta];
45         }
46     }
47 
48     int q = read();
49     while (q--)
50     {
51         int m = read(), sta = 0;
52         for (int i = 1; i <= m; i++) sta |= 1 << read() - 1;
53         int k = read();
54 
55         int l = 0, r = n + 1;
56         while (l < r)
57         {
58             int mid = (l + r) >> 1;
59             if (check(mid, sta, k)) r = mid;
60             else l = mid + 1;
61         }
62 
63         if (l == 0 || l == n + 1) { puts("-1"); continue; }
64 
65         for (int i = 20; ~i; i--)
66         {
67             if (l - (1 << i) <= 0) continue;
68             if (pri[l - (1 << i)][sta] == pri[l][sta]) l -= (1 << i);
69         }
70         printf("%d\n", s[l].p);
71     }
72     return 0;
73 }
View Code

T3:

  暴力

T4:

  暴力

总结:

  早上起晚了,来晚了五十分钟,多这四十多分钟可能能再写二十几分吧

 

posted on 2020-11-01 18:46  ArrogHie  阅读(114)  评论(0)    收藏  举报