A. Sweet Problem (CF 1263 A)

题目大意:你有不同数量的红绿蓝三种颜色的糖果,每天想吃两颗颜色不同的糖果,问能吃多少天。

2019ICPC沈阳赛区flowers的弱化题qwqflowers是有n种花选m种不同种类的一朵花组成一束花问最多能组成多少束。

是否可行具有单调性,二分天数,只要选的糖果数小于等于天数,就一定存在某种方案,不会出现某一天吃两只同样的糖果。

 

 1 #include <bits/stdc++.h>
 2 #define MIN(a,b) ((((a)<(b)?(a):(b))))
 3 #define MAX(a,b) ((((a)>(b)?(a):(b))))
 4 #define ABS(a) ((((a)>0?(a):-(a))))
 5 using namespace std;
 6 
 7 template <typename T>
 8 void read(T &x) {
 9     int s = 0, c = getchar();
10     x = 0;
11     while (isspace(c)) c = getchar();
12     if (c == 45) s = 1, c = getchar();
13     while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
14     if (s) x = -x;
15 }
16 
17 template <typename T>
18 void write(T x, char c = ' ') {
19     int b[40], l = 0;
20     if (x < 0) putchar(45), x = -x;
21     while (x > 0) b[l++] = x % 10, x /= 10;
22     if (!l) putchar(48);
23     while (l) putchar(b[--l] | 48);
24     putchar(c);
25 }
26 
27 int r,b,g,sum;
28 
29 void Input(void) {
30     read(r);
31     read(b);
32     read(g);
33     sum=r+b+g;
34 }
35 
36 bool check(int x){
37     int a=MIN(x,r);
38     int u=MIN(x,b);
39     int v=MIN(x,g);
40     if (u+a+v>=2*x) return 1;
41     else return 0;
42 }
43 void Solve(void) {
44     int l=0,r=1e9;
45     int ans=0;
46     while(l<r){
47         int mid=(l+r)>>1;
48         if (check(mid)) ans=mid,l=mid+1;
49         else r=mid;
50     }
51     printf("%d\n",ans);
52 }
53 
54 void Output(void) {}
55 
56 main(void) {
57     int kase;
58     freopen("input.txt", "r", stdin);
59     freopen("output.txt", "w", stdout);
60     read(kase);
61     for (int i = 1; i <= kase; i++) {
62         //printf("Case #%d: ", i);
63         Input();
64         Solve();
65         Output();
66     }
67 }
神奇的代码

相关文章:

  • 2022-02-23
  • 2021-07-31
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2021-08-12
猜你喜欢
  • 2021-07-05
  • 2021-12-29
  • 2021-12-03
  • 2021-06-13
  • 2021-09-19
相关资源
相似解决方案