您的位置:首页 > 其它

思维题题集--------一直都很害怕这些题

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

#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐