uva uva 1612 - Guess
2015-08-16 23:41
381 查看
// // main.cpp // uva 1612 - Guess // // Created by XD on 15/8/16. // Copyright (c) 2015年 XD. All rights reserved. // /* 暴力枚举 + 精度 + 二分查找 此题并不难。。最后一名的可能获得分数最多有8种。只要枚举就行了。 然后就是判断这个分数是否可行。 关键就是判断这个分数是不是可行上。 当确定了最后一名的分数后,那么倒数第二位的分数可以去多少呢? 最多可能也会有8种选择。这里就是贪心的地方。我们只要当前的分数尽可能接近于排名后一位的选手,也就是说当前选手的得分score[i] - score[i+1] 最小。因为这样后面的选择会更多,也是最大可能满足题目给定的排名。如果这样都不可能的话,那么当前的最后一名的得分是不可能满足题意的。 (假设能够满足题意,我们假设上面的判断在第k个选手处,score[k]>= score[k+1] 的不可能,也就是说score[k]的最大值是小与或者大于score[k+1]的某个值。现在考虑存在的一种情况满足题意,那么就出现了一个矛盾---这个情况下存在 score[k] > score[k+1])。 这里再采用以下二分查找,又降低了复杂度。 总的复杂度是 O(8 * 3 * n ) . */ #include <iostream> #include <string> #include <queue> #include <stack> #include <stdio.h> #include <stdlib.h> #include <math.h> #include<vector> #include <string.h> #include <string> #include <algorithm> #include <set> #include <map> #include <cstdio> using namespace std ; int maxscore = 30000000 ; const int maxn = 16390 + 5 ; int perm[maxn] ; int score[maxn][9] ; int n ; int canfind_bigger(int pos , int s) { int num = *lower_bound(score[pos], score[pos] + 9 , s) ; if (num == maxscore) { return -1 ; } else{ return num ; } } int judge(int s) { for (int i = n-2 ; i>-1; i--) { s = perm[i+1] < perm[i] ?canfind_bigger(perm[i]-1, s + 1):canfind_bigger(perm[i]-1, s) ; if (s == -1) { return 0 ; } } return 1 ; } int main(int argc, const char * argv[]) { double a,b,c ; int ta,tb,tc ; int kase = 0 ; while (scanf("%d" ,&n) , n ) { for (int i = 0; i < n ; i++) { scanf("%lf%lf%lf" ,&a,&b,&c) ; ta = (a+ 0.005) *100.0; tb = (b +0.005)*100.0 ; tc = (c+0.005)*100.0 ; int t = 0 ; for (int j= 0;j < 2 ; j++) { for (int k = 0 ; k < 2; k++) { for (int l = 0 ; l < 2; l++) { score[i][t++] = ta * j + tb* k + tc * l ; } } } score[i][8] = maxscore ; sort(score[i], score[i] + 9) ; } for (int i = 0; i < n; i++) { scanf("%d", &perm[i]) ; } printf("Case %d: " , ++kase) ; int last = -1 ;int flag = 1 ; for (int i = 7; i >-1 ; i--) { if (score[perm[n-1]-1][i] != last ) { last =score[perm[n-1]-1][i] ; if (judge(last)) { flag = 0 ; printf("%.2f\n" ,((double)(last)) / 100); break ; } } } if (!flag) { continue ; } printf("No solution\n") ; } return 0; }
相关文章推荐
- 【Android】高仿QQ 5.0+ UI
- POJ 1679 The Unique MST(次小生成树模板)
- 高效e人注册码 EfficientPIM Pro 3.81 Build 377
- Longest Common Subsequence (LCS)
- 安装J2EE的SDK报错:could not find the required version of the Java(TM)2 Runtime Environment in '(null)'的解决
- Codeforces Round #316 D. Tree Requests 树剥分
- 超详细!iOS 并发编程之 Operation Queues
- UIViewConroller(控制器)间关系
- Java 生成 UUID
- 去掉UUID的小横线,如果你觉得不爽的话,哈哈
- UE4学习笔记(一):初识UE4
- 去哪网实习总结:easyui在JavaWeb中的使用,以datagrid为例(JavaWeb)
- leetcode 128: Longest Consecutive Sequence
- 最长上升子序列 LIS(Longest Increasing Subsequence)(转)
- 1151 - Buy or Build (最小生成树)
- 机房合作总结
- HDU 5301(Buildings-贪心构造)
- iOS UI 视图移动及缩放
- Codeforce466A——贪心——DZY Loves Sequences
- HDU 2227-Find the nondecreasing subsequences(dp+BIT优化)