Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)
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)的更多相关文章
- Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]
哎,最近弱爆了,,,不过这题还是不错滴~~ 要考虑完整各种情况 8795058 2014-11-22 06:52:58 njczy2010 B - Ca ...
- Codeforces Round #278 (Div. 2)
题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...
- 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 ...
- 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/ ...
- CodeForces Round #278 (Div.2) (待续)
A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...
- Codeforces Round #278 (Div. 1)
A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang an ...
- codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)
题意:打怪兽.可增加自己的属性,怎样在能打倒怪兽的情况下花费最少? 这题关键要找好二分的量.一开始我觉得,只要攻击到101,防御到100,就能必胜,于是我对自己的三个属性的和二分(0到201),内部三 ...
- 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 ...
- Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp
D - Conveyor Belts 思路:分块dp, 对于修改将对应的块再dp一次. #include<bits/stdc++.h> #define LL long long #defi ...
随机推荐
- [Aaronyang] 写给自己的WPF4.5 笔记18[几何图形*Geometry图文并茂讲解]
为什么要掌握?因为WPF 3D知识很多与它Geometry对比,所以我要系统学一下. --学会用Geometry给Path的Data属性填充. 图形可以转换成路径,Path的值,当然你也可以直接使用R ...
- [Lua]50行代码的解释器,用来演示lambda calculus
嗯,来写写经过: 在知乎上看见用Belleve牛用javascript写了一个精简的lisp解释器 => 我也想写一个,用lua写,能多简单呢? => 写了一个阉割的scheme解释器,包 ...
- 读匿名object对象的属性值
读匿名object对象的属性值 1.定义读object对象值的功能方法 public static class StaticClass { public static string ValueByKe ...
- 彻底解决Android SDK Manager更新慢的问题
Android SDK 下载速度慢,解决方法大概有两种.第一,FQ.这种方法比较彻底,但是要想有稳定的效果还的要花大价钱.第二,有些高人直接给了SDK中各软件的下载地址,直接下载速度非常快,下载后将包 ...
- TSPL学习笔记(4):数组相关练习
最近研究函数式编程,都是haskell和scheme交互着看的,所以笔记中两种语言的内容都有,练习一般也都用两种语言分别实现. 本篇练习一些数组有关的问题,之所以与数组相关是因为在命令式编程中以下问题 ...
- Log4Net简单使用
一. Log4net是什么.优点 用来记录程序日志,优点:1.提供应用程序运行时的精确环境,可供开发人员尽快找到应用程序中的Bug:2.日志信息可以输出到不同的地方(数据库,文件,邮箱等). 二. L ...
- (笔记)VC6插件安装--Unable to register this add-in because its DllRegisterServer returns an error
在安装插件(如VC6显示行号的插件VC6LineNumberAddin.dll)的时候经常会提示"Unable to register this add-in because its Dl ...
- 网站CSS选择器性能讨论
CSS选择符由一些初始化参数组成,这些参数指明了要应用这个CSS规则的页面元素.作为一个网站的前端开发工程师,应该避免编写一些常见的开销很大的CSS选择符模式,尽量编写高效的CSS选择符,从而加快页面 ...
- [转]C++学习–基础篇(书籍推荐及分享)
C++入门 语言技巧,性能优化 底层硬货 STL Boost 设计模式 算法篇 算起来,用C++已经有七八年时间,也有点可以分享的东西: 以下推荐的书籍大多有电子版.对于技术类书籍,电子版并不会带来一 ...
- django shell 集合
1.创建project $ django-admin startproject mysite 2.真正执行,修改数据库 $ python manage.py migrate 3.运行服务 $ pyth ...