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 ...
随机推荐
- node中使用domain处理异步异常问题
domain实际上是一个隔离容器,将一个或者多个eventEmiter放入容器中,这样由该event发出的事件,如果出现异常就会最终被该domain捕获. demo代码可参见: var EventEm ...
- wwdc2016-session707 Notifications(draft)
Introduction to Notificationshttps://developer.apple.com/wwdc2016/707 通知这哥们说话有点不清晰啊. 远程通知本地通知 可以被操作的 ...
- 解决mac os x下 tomcat启动报 java.net.BindException: Permission denied <null>:80 错误
我在mac os x上启动tomcat的时候,报 java.net.BindException: Permission denied <null>:80,java.net.BindExce ...
- windows server 2003 ODBC数据源配置错误
1.ODBC 数据源链接失败,错误 :STATE hy000, 不能产生SSPI上下文, 2.文件服务器,TCP/IP协议属性中,DNS没有填写,填入DNS即可解决.
- DB2解除锁表
背景 生产环境中,我几乎没有遇到过锁表.多是在开发过程中遇到的,比如团队开发中经常会遇到多个功能访问同一张表的情况.如果有开发人员在这张表加了排它锁,然后又忘记提交事务,那么其他开发人员就要一直等待了 ...
- U盘FAT32转换NTFS格式
运行----cmd----convert x:/fs:ntfs回车 x标识你的U盘或硬盘盘符 比如你的U盘是H盘,那就是h:/fs:ntfs FAT32----NTFS是不可逆转的转换.
- 安卓TTS语音合成经验分享(科大讯飞语音+)集成
应用场景:足浴软件,技师钟房安排调派和队列排序查看,语音播报提醒.老程序是使用双屏显卡,windows系统PC上运行一个无人值守桌面程序.如今安卓机顶盒(WIFI)和MINI电视棒通过HDMI接口和支 ...
- 在linux安装mysql,并设置远程访问
1.查看系统有没有安装mysql. vpm -qa mysql 发现有删除:rpm -e mysql(rpm -e --nodeps mysql) 2.下载数据库 mysql-standard-5.0 ...
- 【NS2仿真】TCP与UDP混合
# # ftp # \ # tcp # \ # n0 sink # \ / # \ / # n1---5M 2ms---n3 # / \ # / \ # n2 null # / # udp # / # ...
- [0x00 用Python讲解数据结构与算法] 概览
自从工作后就没什么时间更新博客了,最近抽空学了点Python,觉得Python真的是很强大呀.想来在大学中没有学好数据结构和算法,自己的意志力一直不够坚定,这次想好好看一本书,认真把基本的数据结构和算 ...