思维题题集--------一直都很害怕这些题
2017-08-17 23:11
225 查看
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4991
给定一个逆波兰表达式,要求添加若干个操作数或者运算符,或者调换任意两个运算符,使得其合法,输出最小步数。
主要思想:分类讨论。
①、当数字大于运算符的时候,可以知道并不需要添加任何数字了,这个时候只考虑交换
②、当数字小于运算符的时候,就一定是要添加数字的。
可以贪心知道,要交换的话,肯定是和最后一个字符交换是最优的。
样例有
***123 ans = 3
1*1 ans = 1
1*1* ans = 1
View Code
给定一个逆波兰表达式,要求添加若干个操作数或者运算符,或者调换任意两个运算符,使得其合法,输出最小步数。
主要思想:分类讨论。
①、当数字大于运算符的时候,可以知道并不需要添加任何数字了,这个时候只考虑交换
②、当数字小于运算符的时候,就一定是要添加数字的。
可以贪心知道,要交换的话,肯定是和最后一个字符交换是最优的。
样例有
***123 ans = 3
1*1 ans = 1
1*1* ans = 1
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(false) using namespace std; #define inf (0x3f3f3f3f) typedef long long int LL; LL x[3][3]; LL dis(LL x1, LL y1, LL x2, LL y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } void work() { for (int i = 0; i < 3; ++i) { for (int j = 0; j < 2; ++j) { scanf("%I64d", &x[i][j]); } } if ((x[1][1] - x[0][1]) * (x[2][0] - x[0][0]) == (x[1][0] - x[0][0]) * (x[2][1] - x[0][1])) { printf("No\n"); return; } if (dis(x[1][0], x[1][1], x[0][0], x[0][1]) == dis(x[1][0], x[1][1], x[2][0], x[2][1])) { printf("Yes\n"); } else printf("No\n"); } int main() { #ifdef local freopen("data.txt", "r", stdin); // freopen("data.txt", "w", stdout); #endif work(); return 0; }
View Code
相关文章推荐
- 一些不为人知的php试题(暂时就总结这些!后续会一直增加 大家觉得不全的请评论或者留言)
- 运营人员,这些产品思维咱必须要懂
- 顶级程序员赢在思维模式,这些区别你注意到了吗?
- 具备这些思维,你才算入了大数据分析的门!
- 一直期望爱情的到来,但是当爱情真的来临的时候我却感到了害怕。。。。。
- 事实上这些都是小顾虑,真正的顾虑在于——害怕输不起!(我雷军为成功概率最高的创业者是在顶级互联网公司工作过四五年的)
- 做一个让黑客也害怕的人,这些你要懂!
- 【玩儿法】真不是装X 为了不加班我一直用这些小众软件
- 大家都知道,木头一直都没有在大的游戏公司待过,没见识也没经历过优秀的项目。最近想研究一些开源的Unity3D框架,开拓一下自己的思维。 优先入坑的是Entitas框架,本系列教程基于0.42.3版本。
- 思维导图在教学中的这些使用技巧你都知道吗?
- 这些常识一直在损害健康
- 一直没了解Firefox还有这些功能
- ❤如果你不想分手,想一直走一辈子。请注意以下这些~·
- 杭电1728————一直WA的BFS(有思维惯性带来的陷阱)
- 这些东西我们一直在寻找
- 这些少数人理财思维你有吗?
- 一直以来电脑只是在不断模拟人类的潜意识部分 - 思维部分就是电脑实现人工智能的目标
- 软件架构——生态思维
- 一直没搞清楚的堆与栈的总结
- 【思维】About ‘New Oriental Way'