UVa 1042 Lots of Sunlight (枚举&最优斜率)
来源:互联网 发布:产品经理设计软件 编辑:程序博客网 时间:2024/05/21 09:52
1042 - Lots of Sunlight
Time limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3483
思路:对于给定的楼层,枚举左、右的最大斜率。
atan(k)/pi就表示所占时间的百分比,注意计算结束时间时要用pi-atan(k)处理下。
提交后居然返回了第一名。。
完整代码:
/*0.118s*/#include<bits/stdc++.h>using namespace std;const double eps = 1e-8;const int BEGIN = (5 * 60 + 37) * 60, END = (18 * 60 + 17) * 60; /// 秒int m[105], d[105], pos[105];int main(){int n, cas = 0, id, Floor, W, H, i, beg, end;double left, right;while (scanf("%d", &n), n){scanf("%d%d", &W, &H);for (i = 1; i < n; ++i){scanf("%d%d", &m[i], &d[i]);pos[i + 1] = pos[i] + W + d[i];}scanf("%d", &m[n]);printf("Apartment Complex: %d\n", ++cas);///while (scanf("%d", &Floor), Floor){id = Floor % 100, Floor /= 100, left = right = 0.0;if (id < 1 || id > n || Floor < 1 || Floor > m[id]){printf("Apartment %d: Does not exist\n", Floor * 100 + id);continue;}for (i = 1; i < id; ++i)if (m[i] >= Floor)left = max(left, (double)((m[i] - Floor + 1) * H) / (pos[id] - pos[i] - W));/// 高度差/距离for (i = id + 1; i <= n; ++i)if (m[i] >= Floor)right = max(right, (double)((m[i] - Floor + 1) * H) / (pos[i] - pos[id] - W));beg = (int)(atan(left) * (END - BEGIN) / M_PI + eps) + BEGIN; ///注意+eps!end = (int)((M_PI - atan(right)) * (END - BEGIN) / M_PI + eps) + BEGIN;printf("Apartment %d: %02d:%02d:%02d - %02d:%02d:%02d\n", Floor * 100 + id, beg / 3600, beg / 60 % 60, beg % 60, end / 3600, end / 60 % 60, end % 60);}}return 0;}
- UVa 1042 Lots of Sunlight (枚举&最优斜率)
- Android have lots of intent
- Do Lots of Deliberate Practice
- Do Lots of Deliberate Practice
- Lots of Buttons的故事
- lots of "GET variable length limit exceeded"
- LOSF(Lots of small files)存储问题
- Island of Logic uva 暴力枚举
- UVA 591 ---Box of Bricks 模拟枚举
- [Linux]oclHashcat Examples of lots of different hash types
- new module add in with lots of issues(part 1)
- new module add in with lots of issues(part 2)
- new module add in with lots of issues(part 3)
- UVa 592 Island of Logic (有趣的枚举题)
- UVa 10344 23 out of 5 (全排列枚举&回溯)
- uva 10439 - Temple of Dune(几何+枚举)
- UVa 10439 - Temple of Dune(非枚举做法)
- uva 12594 斜率优化dp
- 直接用域名取网络地址操作
- mantisbt1.2.5安装配置
- SSH
- 第三章 Windows and Messages
- 最长回文串
- UVa 1042 Lots of Sunlight (枚举&最优斜率)
- 时间子系统10_hpet时钟初始化
- java插入算法
- hdu 1281 棋盘游戏 (二分图匹配)
- 机器学习算法与Python实践之(一)k近邻(KNN)
- java servlet + ajax乱码
- jQuery和struts2返回生成json数据
- DNN交互设计-Panels可收缩界面(四)
- Working Practice-开发时间效率值