poj 1654 Area
来源:互联网 发布:qq号码定位软件 编辑:程序博客网 时间:2024/06/13 07:36
求面积, 注意用 long long, 而用double不行,还有就是最后求出的面积(即sum/2)乘以2 将面积看成 多个 一半的小正方形,
如果是奇数就面积(sum/2)+0.5 偶数就直接输出
#include <iostream>#include <cstdio>#include <string>#include <cmath>using namespace std;string str;int x, y, flag;void Ijs(int i){ if(i == 5) flag = 1; else if(i == 8) y += 1; else if(i == 2) y -= 1; else if(i == 6) x += 1; else if(i == 4) x -= 1; else if(i == 9) x += 1, y += 1; else if(i == 7) x -= 1, y += 1; else if(i == 3) x += 1, y -= 1; else if(i == 1) x -= 1, y -= 1;}int main(){// #ifndef ONLINE_JUDGE// freopen("in.txt","r",stdin);// #endif // ONLINE_JUDGE int t; scanf("%d", &t); while(t--) { flag = 0; x = y = 0; cin >> str; if(str[0] == '5') { cout << 0 << endl; continue; } int len = str.size(); long long sum = 0; int kx, ky, a; kx = 0, ky = 0; for(int i = 0; i < len; i++) { a = str[i]-'0'; Ijs(a); if(flag) break; sum += kx*y-x*ky; kx = x, ky = y; } if(sum<0) sum = -sum; if(sum%2) printf("%I64d.5\n", sum/2); else printf("%I64d\n", sum/2); }}
- poj 1654 Area
- POJ 1654 Area
- POJ 1654 Area
- poj 1654 Area
- POJ 1654 Area
- poj 1654Area
- poj 1654 Area
- POJ 1654 Area
- POJ 1654 Area
- poj 1654 Area
- poj 1654 Area
- POJ 1654 Area
- POJ 1654 Area
- POJ 1654 Area
- poj 1654 Area
- POJ 题目1654Area
- poj 1654 Area
- poj 1654 Area
- 黑马程序员:Java基础篇之多线程
- 纹理过滤
- 新玩的windows phone app studio
- linux下firefox,无法打开flash中的链接,总是被firefox自带的弹窗阻拦器阻挡
- Shell变量功能(2)
- poj 1654 Area
- Relationship between java file name and the declared class name in it
- MFC编译链接正确 但运行不出界面
- override和overload的区别
- Find a multiple
- LeetCode-Climbing Stairs
- [unity 基础教程]给着色器shader添加透明属性
- spoj 379
- C基础:函数