hdu 1557暴力枚举
2013-06-01 16:19
267 查看
数据小,水题,直接穷举每一种组合,然后相应判断处理即可。
/* * hdu1557/win.cpp * Created on: 2013-6-1 * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <set> #include <map> #include <stack> #include <string> #include <vector> #include <deque> #include <list> #include <functional> #include <numeric> #include <cctype> using namespace std; const int MAXN = 22; int data[MAXN], result[MAXN], total; int indexs[MAXN]; double half; void initindexs() { for(int i = 0; i < MAXN; i++) { indexs[i] = 1 << i; } } void work(int state, int n) { int to = 0; for(int i = 0; i < n; i++) { if(state & indexs[i]) { to += data[i]; } } if(to <= half) { return ; } for(int i = 0; i < n; i++) { if((state & indexs[i]) && to - data[i] <= half) { result[i]++; } } } int main() { #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif int T, n; initindexs(); scanf("%d", &T); while(T--) { scanf("%d", &n); memset(result, 0, sizeof(result)); total = 0; for(int i = 0; i < n; i++) { scanf("%d", &data[i]); total += data[i]; } half = total / 2.0; int max_state = 1 << n; for(int state = 0; state < max_state; state++) { work(state, n); } printf("%d", result[0]); for(int i = 1; i < n; i++) { printf(" %d", result[i]); } putchar('\n'); } return 0; }
相关文章推荐
- HDU 2021 发工资咯:)(暴力枚举)
- hdu 3325 Arithmetically Challenged(dfs全排+暴力枚举破解+set集合的应用)
- HDU 5137 How Many Maos Does the Guanxi Worth 暴力枚举+图论
- hdu 4445 暴力枚举
- hdu 5128 The E-pang Palace(计算几何,暴力枚举)
- HDU 5616 dp/暴力枚举
- hdu 4770 Lights Against Dudely(暴力枚举dfs)
- hdu_5616_Jam's balance(暴力枚举子集||母函数)
- HDU 6077 Time To Get Up -暴力枚举-2017多校联盟4 第11题
- HDU 1598 find the most comfortable road 【暴力枚举 + 并查集】
- HDU 3823 暴力枚举
- hdu 5726 区间gcd RMQ+二分 || 暴力枚举
- hdu 5660 暴力枚举
- hdu 1172 猜数字(暴力枚举)
- hdu 1239 Calling Extraterrestrial Intelligence Again (暴力枚举)
- hdu 5128 The E-pang Palace(计算几何,暴力枚举)
- hdu 4770 Lights Against Dudely(暴力枚举dfs)
- hdu_5616_Jam's balance(暴力枚举子集||母函数)
- HDU 4331Image Recognition2012多校第四场A题(暴力枚举+小技巧)
- hdu 5143 NPY and arithmetic progression(暴力枚举)