uva10670 - Work Reduction
来源:互联网 发布:java replacefirst 编辑:程序博客网 时间:2024/06/07 11:21
题意:
老板给你n个任务,你只能最多留m个,你干不了就辞了你,现在一个机构能帮你完成任务,有A,B两种方案,金额不同,A能帮你完成1个,B能帮你完成当前的一半。
思路:
贪心的思路,题目要求的其实就是关于A,B的选择,如过当前扣掉一半后所得>=m而且经费画得比A少就选B,否则就选择A
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 105;struct comp{ char name[20]; int A, B; int cnt;}a[N];char str[N];int cmp(comp a,comp b) { if (a.cnt != b.cnt) return a.cnt < b.cnt; else return strcmp(a.name, b.name) < 0;}int n, m, l;int main() { int cas, Case = 0; scanf("%d", &cas); while (cas--) { scanf("%d%d%d\n", &n, &m, &l); for (int i = 0; i < l; i++) { //scanf_s("%s:%d,%d\n", a[i].name, &a[i].A, &a[i].B); gets(str); int j; for (j = 0; str[j] != ':'; ++j) a[i].name[j] = str[j]; a[i].name[j] = '\0'; sscanf(str + j + 1, "%d,%d", &a[i].A, &a[i].B); a[i].cnt = 0; } for (int i = 0; i < l; i++) { int left = n; int A = a[i].A, B = a[i].B; int mid = (left + 1) / 2; while (left - mid >= m &&B <= mid*A) { a[i].cnt += B; left -= mid; mid = (left + 1) / 2; } if (left>m) a[i].cnt += (left - m)*A; } printf("Case %d\n", ++Case); sort(a, a + l, cmp); for (int i = 0; i < l; i++) printf("%s %d\n",a[i].name,a[i].cnt); } return 0;}
0 0
- UVA10670-Work Reduction
- uva10670 - Work Reduction
- uva10670 - Work Reduction(减轻工作)
- [贪心&&排序]UVA10670 Work Reduction
- POJ 1907 Work Reduction
- UVa 10670 - Work Reduction
- UVa 10670 - Work Reduction
- uva 10670 - Work Reduction
- 10670 - Work Reduction
- UVaOJ10670 - Work Reduction
- UVA 10670 Work Reduction
- UVA 10670 - Work Reduction
- uva 10670 - Work Reduction
- uva 10670 Work Reduction
- UVa:10670 Work Reduction
- uva 10670 - Work Reduction
- UVa 10670 - Work Reduction
- uva 10670 Work Reduction
- Flask--实现密码散列以及@property用法
- PAT_Basic --- 1006
- oracle学习—视图、序列、索引、约束练习
- C#成魔之路<4>C#面向对象高级技术(2)
- HDOJ 1027-Ignatius and the Princess II【全排列】
- uva10670 - Work Reduction
- vi编辑器的使用
- 程序员笔试面试复习【算法篇之内部排序】
- 股市陷阱
- Comparable 和comparator
- 单例模式
- JavaScript跨域总结与解决办法
- STL之Vector
- 不同浏览器存放cookie的路径是不一样的