CF488 B.Candy Boxes

数学+暴力

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<string>
 6 #include<queue>
 7 #include<algorithm>
 8 #include<map>
 9 #include<iomanip>
10 #include<climits>
11 #include<string.h>
12 #include<numeric>
13 #include<cmath>
14 #include<stdlib.h>
15 #include<vector>
16 #include<stack>
17 #include<set>
18 #define FOR(x, b, e)  for(int x=b;x<=(e);x++)
19 #define REP(x, n)     for(int x=0;x<(n);x++)
20 #define INF 1e7
21 #define MAXN 100010
22 #define maxn 1000010
23 #define Mod 1000007
24 #define N 1010
25 using namespace std;
26 typedef long long LL;
27
28 int x[5];
29 int n;
30 bool gao(int *y)
31 {
32     int cnt = 0;
33     bool vis[4] = {0};
34     for (int i = 0;i < n;++ i) {
35         for (int j = 0;j < 4;++ j) {
36             if (!vis[j] && y[j] == x[i]) {
37                 vis[j] = 1;
38                 cnt++;
39                 break;
40             }
41         }
42     }
43     if (cnt == n) {
44         puts("YES");
45         for (int i = 0;i < 4;++ i)
46             if (!vis[i]) cout << y[i] << endl;
47         exit(0);
48     }
49     return false;
50 }
51
52 int main()
53 {
54     cin >> n;
55     for(int i = 0;i < n;++ i)
56         cin >> x[i];
57     for (int i = 1;i <= 500;++ i)
58         for (int j = i;j <= 2*i ;++ j) {
59             int y[] = {i, j,4*i - j,3*i};
60             gao(y);
61         }
62     puts("NO");
63     return 0;
64 }
时间: 2024-08-30 04:07:58

CF488 B.Candy Boxes的相关文章

Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]

哎,最近弱爆了,,,不过这题还是不错滴~~ 要考虑完整各种情况 8795058                 2014-11-22 06:52:58     njczy2010     B - Candy Boxes             GNU C++     Accepted 31 ms 4 KB 8795016                 2014-11-22 06:48:15     njczy2010     B - Candy Boxes             GNU C+

cf B Inna and Candy Boxes

题意:输入n,然后输入n个数ai,再输入n个数bi,如果在1-ai中能找到两个数x,y,x和y可以相等,如果x+y=bi,答案加上x*y,否则减去1,让结果尽可能大,输出结果. 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define ll long long 5 #define maxn 100100 6 using namespace std; 7 8 int n; 9 ll

cf C. Inna and Candy Boxes

题意:给你一个长度为n的只含有1和0的字符串,w个询问,每次询问输入l,r:在[l,r]中在l+k-1.l+2*k-1.......r的位置都必须为1,如果不为1的,变成1,记为一次操作,其它的地方的都必须为0,不为0的地方要变成1,也记为一次操作,最后问在区间[l,r]最少几次操作. 思路:可以用树状数组记录在某个地方的右方有多少个1,然后在 预处理出从1,2,..k的为开头的在i+c*k-1的位置上前面有多少个1,最后的答案是拿走的1+添加的1,拿走的1的个数等于现有的1的个数-位置正确的1

hdu 4465 Candy (快速排列组合 )

Candy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2115    Accepted Submission(s): 910 Special Judge Problem Description LazyChild is a lazy child who likes candy very much. Despite being ve

HDU 4465 Candy

Candy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2520    Accepted Submission(s): 1100Special Judge Problem DescriptionLazyChild is a lazy child who likes candy very much. Despite being very

Candy( 数学期望 )

Candy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1830    Accepted Submission(s): 794 Special Judge Problem Description LazyChild is a lazy child who likes candy very much. Despite being ve

HDU 4465 Candy(组合+log优化)

题目大意:给你两个罐子,里面有糖果每次只能从一个罐子里面取一个糖果,打开A的概率为p,问当一个罐子取完之后,另一个罐子剩糖果的期望是多少. 我们可以知道最少是取第n+1次的时候才会有一个罐子为空,我们可以推出组合公式: (n-k)*C(n+k, k)*((1-p)^(n+1)*p^k+(1-p)^k*p^(n+k)):0 <= k && k <= n-1. 求一个和就是所有的组合情况了,但是组合数很大我们可以用log来进行优化. 我们已知:C(n,m) = m!/n!/(m-n

uva 1639--精度处理方法之取对数对数(uva 1639)

1639 - Candy Time limit: 3.000 seconds 1639 CandyLazyChild is a lazy child who likes candy very much. Despite being very young, he has two large candy boxes, each contains n candies initially. Everyday he chooses one box and open it. He chooses the ?

dp题目列表

10271 - Chopsticks 10739 - String to Palindrome 10453 - Make Palindrome 10401 - Injured Queen Problem 825 - Walking on the Safe Side 10617 - Again Palindrome 10201 - Adventures in Moving - Part IV 11258 - String Partition 10564 - Paths through the Ho