B. Candy Boxes

Problem's Link:   http://codeforces.com/contest/488/problem/B


Mean:

T题目意思很简单,不解释。

analyse:

这道题还是很有意思的,需要考虑到各种情况才能AC。

解这个题目之前,首先要推出两条式子

  x4=3x1
  4x1=x2+x3

然后就是分类讨论,枚举各种情况就可。

Time complexity: O(1)

Source code: 

//  Memory   Time
// 1347K 0MS
// by : Snarl_jsb
// 2014-11-26-21.20
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<climits>
#include<cmath>
#define N 1000010
#define LL long long
using namespace std; int ans[10], input[10];
bool flag = true;
bool Solve(int n)
{
if (n == 0)
{
puts("YES");
printf("%d\n%d\n%d\n%d\n", 1, 1, 3, 3);
}
if (n == 1)
{
puts("YES");
ans[1] = input[1], ans[4] = ans[1] * 3, ans[2] = ans[1], ans[3] = ans[4];
for (int i = 2; i <= 4; i++) printf("%d\n", ans[i]);
}
if (n == 2)
{
if (input[2] % 3)
{
if (input[1] * 3 < input[2]) return flag = false;
puts("YES");
ans[1] = input[1], ans[4] = ans[1] * 3;
int tmp = 4 * ans[1] - input[2];
printf("%d\n%d\n", ans[4], tmp);
}
else
{
if (input[2] / 3 > input[1]) return flag = false;
puts("YES");
ans[1] = input[2] / 3;
int tmp = 4 * ans[1] - input[1];
printf("%d\n%d\n", ans[1], tmp);
}
}
if (n == 3)
{
if (input[3] % 3)
{
if (input[1] * 3 < input[3]) return flag = false;
for (int i = 1; i <= 3; i++) ans[i] = input[i];
ans[4] = ans[1] * 3;
if (4 * ans[1] != ans[2] + ans[3]) return flag = false;
puts("YES");
printf("%d\n", ans[4]);
}
else
{
if (input[3] / 3 > input[1]) return flag = false;
if (input[3] / 3 == input[1])
{
puts("YES");
printf("%d\n", input[1] * 4 - input[2]);
return true;
}
ans[1] = input[3] / 3, ans[4] = input[3], ans[2] = input[1], ans[3] = input[2];
if (4 * ans[1] != ans[2] + ans[3]) return flag = false;
puts("YES");
printf("%d\n", ans[1]);
}
}
if (n == 4)
{
for (int i = 1; i <= 4; i++) ans[i] = input[i];
if (4 * ans[1] == ans[2] + ans[3]) puts("YES");
else flag = false;
}
} int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
// freopen("C:\\Users\\ASUS\\Desktop\\cin.cpp","r",stdin);
// freopen("C:\\Users\\ASUS\\Desktop\\cout.cpp","w",stdout);
int n, i, j;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &input[i]);
sort(input + 1, input + n + 1);
Solve(n);
if (!flag)
{
puts("NO");
return 0;
}
return 0;
}
/* */

  

Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)的更多相关文章

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

    哎,最近弱爆了,,,不过这题还是不错滴~~ 要考虑完整各种情况 8795058                 2014-11-22 06:52:58     njczy2010     B - Ca ...

  2. Codeforces Round #278 (Div. 2)

    题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...

  3. Codeforces Round #278 (Div. 1) B. Strip multiset维护DP

    B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B De ...

  4. Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力

    A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/ ...

  5. CodeForces Round #278 (Div.2) (待续)

    A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...

  6. Codeforces Round #278 (Div. 1)

    A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang an ...

  7. codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)

    题意:打怪兽.可增加自己的属性,怎样在能打倒怪兽的情况下花费最少? 这题关键要找好二分的量.一开始我觉得,只要攻击到101,防御到100,就能必胜,于是我对自己的三个属性的和二分(0到201),内部三 ...

  8. Codeforces Round #278 (Div. 2) D. Strip 线段树优化dp

    D. Strip time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  9. Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp

    D - Conveyor Belts 思路:分块dp, 对于修改将对应的块再dp一次. #include<bits/stdc++.h> #define LL long long #defi ...

随机推荐

  1. 常用的sql脚本 游标遍历操作

    Declare @id int DECLARE cursor_data CURSOR FOR --这里是取得数据源 OPEN cursor_data FETCH FROM cursor_data IN ...

  2. 菜鸟调错(七)——控制台中执行mvn命令后提示‘cmd’不是内部或外部命令

    最近在cmd下使用mvn命令时,在执行完以后总会出现一句“‘cmd’不是内部或外部命令,也不是可执行程序或批处理文件”,如下图: 虽然命令执行成功了,不会有什么影响,但是身为强迫症晚期的我是绝对不能忍 ...

  3. JPA与Hibernate的关系

    1.JPA JPA全称: Java Persistence API  JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中.  JPA的出现?  JPA ...

  4. 送给大家一个安卓版的easyradius短信提示客户端

    好像木有写博客了,送大家小软件,后期会适当更新 主要是方便一些用手机给用户发送到期短信的用户 下载地址: http://www.yss58.com/yss58

  5. The model backing the <Database> context has changed since the database was created.

    Just found out the answer and thought of updating here. Just need to do the following. public class ...

  6. 使用Struts+Hibernate开发学生信息管理系统

    1.项目组织结构 2.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app vers ...

  7. CSS基础(七):z-index详解

    概念 z-index 属性设置元素的堆叠顺序.拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面. 层级关系的比较 1. 对于同级元素,默认(或position:static)情况下文档流后面的 ...

  8. AX 与Citrix打印机问题

    国外文章,抄个链接,备查 http://blogs.msdn.com/b/axsupport/archive/2010/07/06/ax-2009-citrix-amp-terminal-server ...

  9. Android关于Theme.AppCompat相关问题的深入分析(转)

    http://www.jianshu.com/p/6ad7864e005e 先来看这样一个错误: No resource found that matches the given name '@sty ...

  10. 读书笔记_Effective_C++_条款四十七:请使用trait classes来表示类型信息

    这一条款主要来讨论模板中迭代器的属性iterator_category,它可以通过类似于vector<int>::iterator::iterator_category的方式来取得. 到这 ...