Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b00a12b

Browse files
committed
Add Solution for polygonarea [OpenKattis]
1 parent 53aaf69 commit b00a12b

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

‎OpenKattis/polygonarea/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<img src="problem.png" />

‎OpenKattis/polygonarea/problem.png

132 KB
Loading[フレーム]

‎OpenKattis/polygonarea/solution.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main(){
6+
int T;
7+
8+
while(cin >> T && T){
9+
vector <pair<int, int> > points;
10+
for (int i = 0; i < T; i++){
11+
int x, y; cin >> x >> y;
12+
points.push_back(make_pair(x, y));
13+
}
14+
points.push_back(make_pair(points[0].first, points[0].second));
15+
double sum = 0.0;
16+
int ccw = 0;
17+
for(int i = 0; i < T; ++i){
18+
double ans = (points[i].first * points[i+1].second) - (points[i].second * points[i+1].first);
19+
ccw += (points[i+1].first - points[i].first) * (points[i+1].second + points[i].second);
20+
sum += ans;
21+
}
22+
if (ccw < 0){
23+
cout << "CCW ";
24+
}else{
25+
cout << "CW ";
26+
}
27+
printf("%.1f\n", abs(sum * 1.0) / 2);
28+
// cout << fixed << setprecision(1) << abs(sum * 1.0) / 2 << endl;
29+
}
30+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /