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. Spark RDD解密

    1.  基于数据集的处理: 从物理存储上加载数据,然后操作数据,然后写入数据到物理设备; 基于数据集的操作不适应的场景: 不适合于大量的迭代: 不适合交互式查询:每次查询都需要对磁盘进行交互. 基于数 ...

  2. 记录一下,如何配置nodejs nginx的反向代理

    本文是在mac下配置nodejs 在nginx下的反向代理 1.安装nodejs,之前就安装了. 2.安装nginx ,我采用的直接源码安装 3.进入 /usr/local/nginx/conf 目录 ...

  3. android 渐变展示启动屏

    启动界面Splash Screen在应用程序是很常用的,往往在启动界面中显示产品Logo.公司Logo或者开发者信息,如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段 ...

  4. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】连载导读

    前言: 无数昼夜的来回轮替以后,这本<驱动篇I>终于编辑完毕了,笔者真的感动到连鼻涕也流下来.所谓驱动就是认识硬件,还有前期建模.虽然<驱动篇I>的硬件都是我们熟悉的老友记,例 ...

  5. ARCGIS10.1 GeoDatabase深入理解:客户端连接与退出地理数据库时系统表的初始化

    平台软件:ARCIGS10.1 ,SQL Server2008R2 目的:了解客户端在连接arcgis 空间地理数据库后,地理数据库会做些什么样的初始化工作 准备工作: 1.准备好数据库日志文件查看工 ...

  6. Hadoop学习笔记(老版本,YARN之前),MapReduce任务Namenode DataNode Jobtracker Tasktracker之间的关系

    一.基本概念 在MapReduce中,一个准备提交执行的应用程序称为“作业(job)”,而从一个作业划分出的运行于各个计算节点的工作单元称为“任务(task)”.此外,Hadoop提供的分布式文件系统 ...

  7. CAS认证原理图

  8. ODAC(V9.5.15) 学习笔记(十五)数据离线模式

    数据离线模式(Disconnected Mode)是指数据库只有在需要的时候才连接,数据的处理放在客户端内存缓冲区中完成.这样做最大的好处是减少了网络资源依赖,对数据库服务器的资源开销和压力也减少.如 ...

  9. 向上下左右不间断无缝滚动图片的效果(兼容火狐和IE)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. POJ 2096 Collecting Bugs

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 1716   Accepted: 783 C ...