Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)
B. Candy Boxes #
Problem's Link: http://codeforces.com/contest/488/problem/B
#
Mean:
analyse:
这道题还是很有意思的,需要考虑到各种情况才能AC。
解这个题目之前,首先要推出两条式子
x4=3x1
4x1=x2+x3
然后就是分类讨论,枚举各种情况就可。
Time complexity: O(1)
Source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | // 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; } /* */ |
作者:北岛知寒
出处:https://www.cnblogs.com/crazyacking/p/4124972.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
标签:
B. Candy Boxes
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?