text
stringlengths
49
983k
#include <bits/stdc++.h> #define chmin(a, b) ((a)=min((a), (b))) #define chmax(a, b) ((a)=max((a), (b))) #define fs first #define sc second #define eb emplace_back using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef pair<double, int> PD; const ll MOD=1e9+7; const ll INF=1e18; int dx[]={0,1,0,-1}; int dy[]={1,0,-1,0}; int main(){ int n,m; cin >> n >> m; vector<int> d[n+10]; for(int i = 0;i < n+5;i++){ d[i].resize(i+10); } for(int i = 0;i < n+5;i++){ for(int j = 0;j < i+1;j++){ d[i][j] = 0; } } for(int i = 0;i < m;i++){ int a,b,x; cin >> a >> b >> x; d[a][b]++; d[a][b+1]--; d[a+x+1][b]--; d[a+x+2][b+1]++; d[a+x+1][b+x+2]++; d[a+x+2][b+x+2]--; } for(int i = 0;i <= n;i++){ for(int j = 1;j <= i+2;j++){ d[i][j] += d[i][j-1]; } } for(int i = 1;i <= n;i++){ for(int j = 0;j <= i+2;j++){ d[i][j] += d[i-1][j]; } } for(int i = 1;i <= n;i++){ for(int j = 1;j <= i+2;j++){ d[i][j] += d[i-1][j-1]; } } int ans = 0; for(int i = 0;i <= n;i++){ for(int j = 0;j <= i+2;j++){ if(d[i][j] > 0) ans++; } } cout << ans << endl; }
#include <cstdio> #include <vector> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int n,m; vector<int> cell[5010]; int main(){ rep(i,5010){ rep(j,i+1) cell[i].push_back(0); } scanf("%d%d",&n,&m); rep(i,m){ int a,b,x; scanf("%d%d%d",&a,&b,&x); a--; b--; cell[a][b] += 1; if(a>=b+1)cell[a][b+1] += -1; cell[a+x+1][b] += -1; cell[a+x+2][b+1] += 1; if(a+x+1>=b+x+2)cell[a+x+1][b+x+2] += 1; if(a+x+2>=b+x+2)cell[a+x+2][b+x+2] += -1; } rep(i,5010) for(int j = 1; j < 5010; j++){ if(i<j||i<j-1)continue; cell[i][j] += cell[i][j-1]; } rep(i,5010) for(int j = 1; j < 5010; j++){ if(j<i||j-1<i)continue; cell[j][i] += cell[j-1][i]; } for(int i = 1; i < 5010; i++) for(int j = 1; j < 5010; j++){ if(i+j>5010) break; if(i+j-1<j||i+j-1<j-1) continue; cell[i+j-1][j] += cell[i+j-2][j-1]; } int ans = 0; rep(i,5010) rep(j,5010){ if(i<j)continue; ans+=(cell[i][j]!=0); } printf("%d\n",ans); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; typedef double ld; #define X first #define Y second #define mk make_pair #define pb push_back #define Rep(i, n) for(int i = 0; i < int(n); i ++) #define Rep1(i, n) for(int i = 1; i <= int(n); i ++) #define all(x) (x).begin(), (x).end() const int MOD = (int) 1e9 + 7; const ll base = 31; void MAIN(); int main(){ //freopen("input.txt", "r", stdin); ios:: sync_with_stdio(false); cin.tie(0); MAIN(); return 0; } //////////////////////////////////////////////////////////////////////// const int N = 5004; int n, m, h[N]; vector <ii> V[N]; void MAIN(){ cin >> n >> m; while(m --){ int a, b, x; cin >> a >> b >> x; V[a + x].pb(ii(b, x+1)); } int ans = 0; for(int i = n; i >= 1; i --){ Rep(j, V[i].size()) h[V[i][j].X] = max(h[V[i][j].X], V[i][j].Y); for(int j = 1; j <= i; j ++){ h[j] = max(h[j], max(0, h[j-1] - 1)); if(h[j]) ans ++; } for(int j = 1; j <= i; j ++) h[j] --; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int wall[5010][5010]; int main(void){ int n,m,a,b,x,i,j,ans=0; fill(wall[0],wall[5010],0); scanf("%d%d",&n,&m); for(i=0; i<m; i++){ scanf("%d%d%d",&a,&b,&x); wall[a][b]++; wall[a][b+1]--; wall[a+x+1][b]--; wall[a+x+1][b+x+2]++; wall[a+x+2][b+1]++; wall[a+x+2][b+x+2]--; } n+=3; for(i=1; i<=n; i++){ for(j=1; j<=n; j++){ wall[i][j]+=wall[i][j-1]; } } for(i=1; i<=n; i++){ for(j=1; j<=n; j++){ wall[i][j]+=wall[i-1][j]; } } for(i=1; i<=n; i++){ for(j=1; j<=n; j++){ wall[i][j]+=wall[i-1][j-1]; } } n-=3; for(i=1; i<=n; i++){ for(j=1; j<=i; j++){ if(wall[i][j]!=0){ ans++; } } } printf("%d\n",ans); return 0; }
#include <iostream> #include <vector> using namespace std; int N, M; vector< vector<bool> > ts; vector< vector<int> > done; void init() { cin >> N >> M; ts.resize(N); done.resize(N); for (int i = 0; i < N; i++) { ts[i].resize(i+1, false); done[i].resize(i+1, -1); } } void enclose(int a, int b, int x) { if (done[a][b] < x) { //if (!ts[a][b]) { ts[a][b] = true; if (x == 0) return; enclose(a+1, b, x-1); enclose(a+1, b+1, x-1); done[a][b] = x; } } int main() { init(); for (int i = 0; i < M; i++) { int A, B, X; cin >> A >> B >> X; A--, B--; enclose(A, B, X); } int cnt = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < ts[i].size(); j++) { // cout << ts[i][j] << ' '; if (ts[i][j]) cnt++; } // cout << endl; } cout << cnt << endl; return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <cassert> #include <iostream> #include <cctype> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <set> #include <stack> #include <map> #include <utility> #include <numeric> #include <algorithm> #include <iterator> #include <bitset> #include <complex> #include <fstream> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef pair<int, int> pint; #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for(int i = x; i < n; i++) template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); } template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; } template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; } template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); } int v[5048][5048]; int main() { int n, m; scanf("%d %d", &n, &m); rep(i, m) { int x, y, l; cin >> y >> x >> l; chmax(v[y][x], l + 1); } int res = 0; REP(y, 1, n + 1) REP(x, 1, y + 1) { chmax(v[y][x], max(v[y-1][x] - 1, v[y-1][x-1] - 1)); res += 0 < v[y][x]; } cout << res << endl; }
#include<iostream> #include<climits> #include<cassert> #include<algorithm> #include<cassert> #include<map> #include<vector> using namespace std; #define REP(i,b,n) for(int i=b;i<n;i++) #define rep(i,n) REP(i,0,n) #define left first #define right second typedef pair<int,int> pii; const int N = 5012; pair<int,int> st[2][N];//ある場所に左端と右端の点が何個あるかを数える。 vector<int> bp[N]; vector<pair<int,int> > ep[N]; /* 各ポイントについて、三角形の左端と右端があるマスとその数を覚えておく。 あとは左端から全部見ていくとその行のうち何個が釘が輪ゴムに覆われているかがわかる。 */ int solve(int n){ rep(i,2)rep(j,n+1)st[i][j].left = 0,st[i][j].right = 0; int ret = 0; REP(i,1,n+1){ rep(j,i+1){ int l = 0,r = 0; if (j-1 >= 0)r = st[0][j-1].right; if (j != i)l = st[0][j].left; st[1][j].left = l; st[1][j].right = r; } rep(j,bp[i].size()){ st[1][bp[i][j]].left++; st[1][bp[i][j]].right++; } /* cout <<i <<" -th line" << endl; rep(j,i+1){ cout << "(" <<st[i][j].left <<"," << st[i][j].right << ") "; } cout << endl; */ int k = 0; rep(j,i+1){ k += st[1][j].left; if (k)ret++; k -= st[1][j].right; assert(k >= 0); } rep(j,ep[i].size()){ st[1][ep[i][j].left].left--; st[1][ep[i][j].right].right--; } rep(j,i+1){ st[0][j] = st[1][j]; st[1][j].left = 0; st[1][j].right = 0; } } return ret; } /**/ int main(){ int n,m; while(cin>>n>>m){ rep(i,N){ bp[i].clear(); ep[i].clear(); } rep(i,m){ int a,b,x; cin>>a>>b>>x; //(Ai, Bi), (Ai + Xi, Bi), (Ai + Xi, Bi + Xi) bp[a].push_back(b); ep[a+x].push_back(make_pair(b,b+x)); //epR[a+x][b+x]++; } cout << solve(n) << endl; } }
#include<bits/stdc++.h> using namespace std; //#define DEBUG #define int long long #define rep(i,n) for(int i=1;i<=n;i++) int n,m; int f[5010][5010]; void debug(){ #ifdef DEBUG rep(i,n+2){ rep(j,n+2)cout<<setw(2)<<right<<f[i-1][j-1]<<" "; cout<<endl; } cout<<endl; #endif } signed main(){ cin>>n>>m; rep(_,m){ int a,b,x; cin>>a>>b>>x; f[a-1][b-1]--; f[a-1][b]++; f[a+x][b-1]++; f[a+x+1][b]--; f[a+x][b+x+1]--; f[a+x+1][b+x+1]++; } int ans=0; debug(); for(int k=n+1;k>=0;k--){ for(int i=n,j=k;i>=0&&j>=0;i--,j--){ f[i][j]+=f[i+1][j+1]; } } debug(); rep(j,n+2){ rep(i,n+1){ f[i][j-1]+=f[i-1][j-1]; } } debug(); rep(i,n){ rep(j,i){ f[i][j]+=f[i][j-1]; if(f[i][j])ans++; } } debug(); cout<<ans<<endl; return 0; }
#include <cstdio> int n,x[50],y[50]; int main(){ for(int c=1;;c++){ float a=0; scanf("%d",&n); if(!n) break; for(int i=0; i<n; i++) scanf("%d %d",&x[i],&y[i]); for(int i=0; i<n; i++) a += 0.5*(x[i]*y[(i+1)%n]-y[i]*x[(i+1)%n]); a *= a>0?1:-1; printf("%d %.1f\n",c,a); } }
#include<iostream> #include<cstdio> #include<cmath> using namespace std; int N; int y[100],x[100]; int main(){ for(int tc=1;;tc++){ cin>>N; if(N==0)break; int ans=0; for(int i=0;i<=N;i++){ if(i<N)cin>>x[i]>>y[i]; else x[i]=x[0],y[i]=y[0]; if(i)ans+=(x[i-1]*y[i])-(x[i]*y[i-1]); } cout<<tc<<' '; printf("%.1f\n",abs(ans*0.5)); } return 0; }
#include <iostream> #include <cstdio> #include <complex> using namespace std; typedef long long ll; typedef double R; typedef complex<R> P; double cross(const P &a, const P &b) { return imag(conj(a)*b); } double dot(const P &a, const P &b) { return real(conj(a)*b); } int n; P p[100]; R solve() { R res = 0; for (int i = 2; i < n; i++) { res += cross(p[i-1]-p[0], p[i]-p[0]) / 2.0; } return abs(res); } int main() { int t = 1; while (true) { scanf("%d", &n); if (!n) break; for (int i = 0; i < n; i++) { R x, y; scanf("%lf %lf", &x, &y); p[i] = P(x, y); } printf("%d %.1f\n", t, solve()); t++; } return 0; }
/* Powered by 0736TuT Code + Music + Games = Life */ #include<iostream> #include<cstdio> #define MAXN 100 typedef long long qwq; using namespace std; class Vector { public: double x,y; double operator *(const Vector &rhs) const {return x*rhs.y-y*rhs.x;} Vector operator -(const Vector &rhs) const { Vector res; res.x=x-rhs.x; res.y=y-rhs.y; return res; } }v[MAXN],lft; int n; double ans=0; int main() { for(int T=1; ;T++) { scanf("%d",&n); if(!n) break; lft.x=123456; for(int i=1;i<=n;i++) { scanf("%lf%lf",&v[i].x,&v[i].y); if(v[i].x<lft.x) lft=v[i]; } for(int i=1;i<=n;i++) v[i]=v[i]-lft; ans=0; for(int i=1;i<n;i++) ans+=v[i+1]*v[i]; ans+=v[1]*v[n]; printf("%d %.1lf\n",T,ans/2); } return 0; }
#include <iostream> #include <iomanip> #include <cstdlib> #include <string> #include <vector> double calc(std::vector<std::vector<int> > coordinate) { int size = coordinate.size(); double area = 0; for (int i = 0; i < size - 1; i++) { area += coordinate[i][0] * coordinate[i + 1][1] - coordinate[i + 1][0] * coordinate[i][1]; } area += coordinate[size - 1][0] * coordinate[0][1] - coordinate[0][0] * coordinate[size - 1][1]; if (area < 0) { area *= (-1); } return area / 2; } int main(void) { int n; int times = 0; std::string ErrorReport; try{ std::cin >> n; while (n != 0) { times++; if (n < 3 || n > 50) { ErrorReport = "n is out of range"; throw ErrorReport; } std::vector<std::vector<int> > coordinate(n, std::vector<int> (2, 0)); for (int i = 0; i < n; i++) { std::cin >> coordinate[i][0]; std::cin >> coordinate[i][1]; } double area = calc(coordinate); std::cout << std::fixed << std::setprecision(1); std::cout << times << " " << area << std::endl; std::cin >> n; } return EXIT_SUCCESS; } catch (std::string ErrorReport){ std::cout << ErrorReport << std::endl; } }
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> using namespace std; int cp(int x[], int y[]){ return x[0]*y[1]-y[0]*x[1]; } int next(int &idx, int n){ ++idx; idx%=n; return idx; } int main(){ int n; cin >> n; int set = 0; while(n){ int x[50][2]; bool used[50]; int s = 0; memset(used,false,sizeof(used)); for(int i = 0; i < n; i++){ cin >> x[i][0] >> x[i][1]; } int idx = 0; int m = n; while(n>=3){ int dx[2][2]; int a; for(int i = 0; i < 2; i++){ a = idx; while(used[next(idx,m)]); dx[i][0] = x[idx][0]-x[a][0]; dx[i][1] = x[idx][1]-x[a][1]; } s += cp(dx[0], dx[1]); used[a] = true; n--; } if(s<0) s*=-1; printf("%d %.1f\n",++set,(double)s/2); cin >> n; } }
#include <cassert> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <ctime> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #include <iostream> #include <algorithm> #include <functional> #include <numeric> #include <string> using namespace std; template <class T> double area_of_polygon(vector<T> x, vector<T> y) { assert(x.size() == y.size()); int n = x.size(); double ret = 0; for (int p = 0; p < n; p++) { for (int i = 1; i <= n - 2; i++) { int q = (p + i) % n, r = (p + i + 1) % n; T v1x, v1y, v2x, v2y; v1x = x[q] - x[p]; v1y = y[q] - y[p]; v2x = x[r] - x[p]; v2y = y[r] - y[p]; ret += v1x*v2y - v1y*v2x; } } ret = abs(ret / (2 * n)); return ret; } int main(void) { int num = 1; while (true) { int n; cin >> n; if (n == 0) { break; } vector<int> x(n), y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } printf("%d %.1lf\n", num++, area_of_polygon(x, y)); } return 0; }
#include <iostream> #include <stdio.h> #include <vector> #include <cmath> using namespace std; class Point { public: int x, y; }; void solve() { int count = 1; int n; while(cin >> n, n) { vector<Point> p(n); for(int i = 0; i < n; ++i) { cin >> p[i].x >> p[i].y; } double sum = 0.0; for(int i = 1; i < n - 1; ++i) { double x1 = p[i].x - p[0].x; double y1 = p[i].y - p[0].y; double x2 = p[i + 1].x - p[0].x; double y2 = p[i + 1].y - p[0].y; sum += x1 * y2 - x2 * y1; } printf("%d %.1f\n", count, abs(sum) / 2); ++count; } } int main() { solve(); return(0); }
#include<bits/stdc++.h> using namespace std; typedef long long int uli; const int mx=60; int x[mx],y[mx]; int main(){ int n,tt=1; while(scanf("%d",&n)==1){ if(n==0)break; for(int i=0;i<n;i++) scanf("%d %d",x+i,y+i); x[n]=x[0],y[n]=y[0]; double area=0; for(int i=1;i<=n;i++){ area+=(y[i]+y[i-1])*(x[i]-x[i-1]); } if(area<0)area*=-1; area*=0.5; printf("%d %.1lf\n",tt++,area); } return 0; }
#include <iostream> #include <cstdio> #include <cmath> using namespace std; typedef struct { int x, y; } POINT; double GetCross( POINT a, POINT b ) { return a.x * b.y - a.y * b.x; } int main( void ) { int n, no = 1; POINT P[51]; while ( cin >> n && n ) { for ( int i = 0; i < n; i++ ) cin >> P[i].x >> P[i].y; for ( int i = 1; i < n; i++ ) P[i].x -= P[0].x, P[i].y -= P[0].y; double area = 0.0; for ( int i = 1; i + 1 < n; i++ ) area += GetCross( P[i], P[i+1] ); area = fabs( area ); area /= 2.0; printf( "%d %.1f\n", no, area ); no++; } return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <stack> #include <algorithm> using namespace std; #define rep(i,j) REP((i), 0, (j)) #define REP(i,j,k) for(int i=(j);(i)<(k);++i) #define between(a,x,b) ((a)<=(x)&&(x)<=(b)) #define F first #define S second #define INF 1 << 30 int main(){ int n, c = 1; while(scanf("%d", &n) && n){ double res = 0; vector<int>x(n+1), y(n+1), x1(n), y1(n); rep(i, n) scanf("%d%d", &y[i], &x[i]); x[n] = x[0]; y[n] = y[0]; rep(i, n) x1[i] = x[i]-x[i+1], y1[i] = y[i]+y[i+1]; rep(i, n) res += x1[i]*y1[i]; res /= 2; printf("%d %.1lf\n", c, res); c++; } return 0; }
#include<iostream> #include<algorithm> #include<cmath> #include<cstdlib> #include<cstdio> #include<vector> using namespace std; #define EPS (1e-10) #define equals(a,b) (fabs((a)-(b)) < EPS) #define curr(P, i) P[(i) % P.size()] #define next(P, i) P[(i+1) % P.size()] #define prev(P, i) P[(i+P.size()-1) % P.size()] typedef pair<int,int> P; class Point{ public: double x,y; Point(double x = 0, double y = 0): x(x),y(y){}; Point operator + (Point p) {return Point(x+p.x,y+p.y);} Point operator - (Point p) {return Point(x-p.x,y-p.y);} Point operator * (double a) {return Point(a*x,a*y);} double own_dot(){return x*x+y*y;}; double abs(){return sqrt(own_dot());} bool operator < (const Point &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator == (const Point &p) const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; } }; // 内積 double dot(Point a, Point b){ return a.x*b.x+a.y*b.y; } // 外積 double cross(Point a, Point b){ return a.x*b.y-a.y*b.x; } //多角形の面積 double area2(vector<Point> P) { double A = 0; for (int i = 0; i < P.size(); ++i) A += cross(curr(P, i), next(P, i)); return abs(A/2); } using namespace std; int main(){ int rev = 0; int n; while(cin >> n && n){ vector<Point> V; rev++; while(n--){ Point p; cin >> p.x >> p.y; V.push_back(p); } printf("%d %.1f\n",rev,area2(V)); } return 0; }
#include <iostream> #include <vector> #include <complex> #include <cstdio> using namespace std; int main () { int counter = 1; int n; while (cin >> n, n) { vector<complex<double> > ps(n); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; ps[i] = complex<double> (x, y); } double area = 0; for (int i = 0; i < n; i++) { area += ps[i].real() * ps[(i+1)%n].imag() - ps[i].imag() * ps[(i+1)%n].real(); } area *= 0.5; area = (area > 0) ? area : -area; printf("%d %.1f\n", counter++, area); } }
#include<iostream> #include<algorithm> #include<vector> using namespace std; class Point { public: double x, y; Point(int x, int y) :x(x), y(y) {} Point operator + (Point p) { return Point(x + p.x, y + p.y); } Point operator - (Point p) { return Point(x - p.x, y - p.y); } }; typedef vector<Point> Polygon; int main() { int cnt = 0; while (1) { int i, j, n; double x, y, s = 0; Polygon p; cin >> n; cnt++; if (n == 0)break; for (i = 0; i < n; i++) { cin >> x >> y; p.push_back(Point(x, y)); } for (i = 1; i < n - 1; i++) { s -= ((p[i] - p[0]).x * (p[i + 1] - p[0]).y - (p[i] - p[0]).y * (p[i + 1] - p[0]).x) / 2.0; } //cout << cnt << " " << s << endl; printf("%d %.1f\n", cnt, s); } return 0; }
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<utility> #include<cstdio> #include<cstdlib> #include<cmath> using namespace std; typedef pair<int,int> PII; typedef long long ll; int main(){ int n,datacase = 1; while(true){ cin>>n; if(!n)break; double area = 0,sx,sy,x1,y1,x2,y2; cin>>x1>>y1; sx = x1,sy = y1; for(int i=0;i<n-1;i++){ cin>>x2>>y2; area+=(y2+y1)*(x2-x1)/2; x1 = x2; y1 = y2; } x2 = sx; y2 = sy; area+=(y2+y1)*(x2-x1)/2; printf("%d %.1f\n",datacase,abs(area)); datacase++; } return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int num = 1; while(1) { int n; cin >> n; if(n == 0) break; vector<double> x(n), y(n); for(int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } double rectangle = 0.0; for(int i = 1; i < n; i++) { double X = x[i] - x[i-1]; double Y = y[i] + y[i-1]; rectangle += X * Y; } double X = x[0] - x[n-1]; double Y = y[0] + y[n-1]; rectangle += X * Y; printf("%d %.1f\n", num, rectangle/2); num++; } return 0; }
#include <iostream> #include <stdio.h> #include <math.h> typedef unsigned long long int ll; using namespace std; int main(){ int n, seq = 0; double s; int x[65], y[65]; while (cin >> n, seq++, n){ for (int i = 0; i < 66; ++i) x[i] = y[i] = 0; for (int i = 1; i <= n; ++i) cin >> x[i] >> y[i]; x[n+1] = x[1]; y[n+1] = y[1]; s = 0; for (int i = 1; i <= n+1; ++i) s += (x[i] * y[i+1]) - (x[i+1] * y[i]); s /= 2; if (s<= 0) s *= -1; printf("%d %.1lf\n", seq, s); } return 0; }
#include <iostream> #include <vector> #include <cassert> namespace boost { template <class T> struct integer_iterator { T a; bool operator != (integer_iterator const & it) const { return a != it.a; } T operator * () const { return a; } integer_iterator & operator ++ () { ++ a; return *this; } integer_iterator operator ++ (int) { return { a ++ }; } }; template <class T> struct integer_range { T l, r; typedef integer_iterator<T> iterator; iterator begin() const { return { l }; } iterator end () const { return { r }; } }; template <class T> integer_range<T> irange(T l, T r) { assert (l <= r); return { l, r }; } template <class T> struct integer_iterator_with_step { T a, d, i; bool operator != (integer_iterator_with_step const & it) const { return a != it.a or d != it.d or i != it.i; } T operator * () const { return a+d*i; } integer_iterator_with_step & operator ++ () { ++ i; return *this; } integer_iterator_with_step operator ++ (int) { return { a, d, i ++ }; } }; template <class T> struct strided_integer_range { T l, r, s; typedef integer_iterator_with_step<T> iterator; iterator begin() const { return { l, s, 0 }; } iterator end () const { return { l, s, (r - l) / s }; } }; template <class T> strided_integer_range<T> irange(T l, T r, T s) { assert (s > 0 ? l <= r : s < 0 ? l >= r : false); return { l, r, s }; } } #include <utility> #include <cmath> #define ttt template <typename T> #define pca point<T> const & ttt struct point { T x, y; }; ttt point<T> operator + (pca a, pca b) { return { a.x+b.x, a.y+b.y }; } ttt point<T> operator - (pca a, pca b) { return { a.x-b.x, a.y-b.y }; } ttt point<T> operator - (pca a) { return { -a.x, -a.y }; } ttt point<T> operator * (T a, pca b) { return { a*b.x, a*b.y }; } ttt std::pair<T,T> to_pair(pca a) { return { a.x, a.y }; } ttt bool operator == (pca a, pca b) { return to_pair(a) == to_pair(b); } ttt bool operator != (pca a, pca b) { return to_pair(a) != to_pair(b); } ttt bool operator < (pca a, pca b) { return to_pair(a) < to_pair(b); } ttt bool operator <= (pca a, pca b) { return to_pair(a) <= to_pair(b); } ttt bool operator >= (pca a, pca b) { return to_pair(a) >= to_pair(b); } ttt bool operator > (pca a, pca b) { return to_pair(a) > to_pair(b); } ttt T length_squared(pca p) { return p.x*p.x + p.y*p.y; } ttt double length(pca p) { return sqrt(length_squared(p)); } ttt point<T> normalized(pca a) { return (1 / length(a)) * a; } ttt T dot(pca p, pca q) { return p.x * q.x + p.y * q.y; } ttt T cross(pca p, pca q) { return p.x * q.y - p.y * q.x; } ttt int ccw(pca a, pca b, pca c) { T x = cross(b - a, c - a); return x > 0 ? 1 : x < 0 ? -1 : 0; } #undef ttt #undef pca template <typename T> std::istream & operator >> (std::istream & input, point<T> & p) { return input >> p.x >> p.y; } template <typename T> std::ostream & operator << (std::ostream & output, const point<T> & p) { return output << p.x << ' ' << p.y; } using namespace std; using namespace boost; int main() { int number = 0; while (true) { int n; cin >> n; if (n == 0) break; vector<point<double> > ps(n); for (auto & p : ps) cin >> p; double area = 0; for (int i : irange(0,n)) { int j = (i+1) % n; area += cross(ps[i], ps[j]); } area = abs(area) / 2; printf("%d %.1lf\n", ++ number, area); } return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; struct Point{ double x, y; }; int main(){ int n; Point P[51]; int cs = 0; while(cin >> n, n){ for(int i = 0 ; i < n ; i++){ cin >> P[i].x >> P[i].y; } double area = 0; for(int i = 0 ; i < n-1 ; i++){ area += P[i].x * P[i+1].y - P[i].y * P[i+1].x; } area += P[n-1].x * P[0].y - P[n-1].y * P[0].x; printf("%d %.1f\n", ++cs, abs(area)/2); } return 0; }
#include <algorithm> #include <functional> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <sstream> #include <iostream> #include <iomanip> #include <vector> #include <list> #include <stack> #include <queue> #include <map> #include <set> #include <bitset> #include <climits> #define all(c) (c).begin(), (c).end() #define rep(i,n) for(int i=0;i<(n);i++) #define pb(e) push_back(e) #define mp(a, b) make_pair(a, b) #define fr first #define sc second const int INF=100000000; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; using namespace std; typedef pair<int ,int > P; typedef long long ll; int n; int x[100],y[100]; double solve() { double s = 0.0; rep(i,n) cin>>x[i]>>y[i]; x[n]=x[0]; y[n]=y[0]; rep(i,n) { s+=x[i]*y[i+1]-x[i+1]*y[i]; } return s/2.0; } int main() { int cnt=1; while(cin>>n) { if(n==0) break; double s = solve(); printf("%d %.1f\n", cnt,-s); cnt++; } return 0; }
#include <iostream> #include <cstdio> #include <cmath> #include <vector> using namespace std; int main(){ int cnt=1; int n; while(cin>>n,n){ double ans=0.0; vector<int>x(n+1),y(n+1); for(int i=0;i<n;i++)cin>>x[i]>>y[i]; x[n]=x[0]; y[n]=y[0]; for(int i=0;i<n;i++){ ans+=(x[i]*y[i+1]-y[i]*x[i+1])*0.5; } printf("%d %.1f\n",cnt++,fabs(ans)); } return 0; }
#include<bitset> #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> using namespace std; /* AOJ 1100 */ const int N = 55; int n, cnt = 0; double ans; struct Point { int x, y; void read(void) { scanf("%d%d", &x, &y); } friend int operator - (Point b, Point a) { return a.x*b.y - b.x*a.y; } }P[N]; signed main(void) { while (scanf("%d", &n), n) { ans = 0; for (int i = 0; i < n; i++) P[i].read(); for (int i = 0; i < n; i++) ans += (double)(P[i] - P[(i + 1) % n]); ans /= 2; printf("%d %.1lf\n", ++cnt, ans); } }
#include <bits/stdc++.h> using namespace std; #define REP(i, s, e) for(int i = (int)(s); i < (int)(e); ++i) #define rep(i, n) REP(i, 0, n) #define X real() #define Y imag() using D = double; using P = complex<D>; using G = vector<P>; const D EPS = 1e-10; namespace std { bool operator < (const P& a, const P& b) { return a.X != b.X ? a.X < b.X : a.Y < b.Y; } }; struct L : array<P, 2> { L () = default; L(const P& a, const P& b) { front() = a; back() = b; } P vec() const { return back() - front(); } }; D dot(const P& a, const P& b) { return (conj(a)*b).X; } D cross(const P& a, const P& b) { return (conj(a)*b).Y; } int ccw(P a, P b, P c) { b -= a; c -= a; if(cross(b, c) > 0) return +1; // ccw if(cross(b, c) < 0) return -1; // cw if(dot(b, c) < 0) return +2; // L c-a-b if(norm(b) < norm(c)) return -2; // L a-b-c return 0; } bool intersectLL(const L& l, const L& m) { return abs(cross(l.vec(), m.vec())) > EPS || abs(cross(l[1] - l[0], m[0] - l[0])) < EPS; } P projection(const L& l,const P& p) { D t = dot(p-l[0], -l.vec()) / norm(-l.vec()); return l[0] + t*(-l.vec()); } P refrection(const L& l, const P& p) { return p + 2.0 * (projection(l, p) - p); } D area(const G& g) { int n = g.size(); D s = 0.0; rep(i, n) { int j = (i+1)%n; s += cross(g[i], g[j]); } return abs(s) / 2.0; } vector<string> split(const string& s, char c = ' ') { stringstream ss(s); vector<string> ret; string t; while(getline(ss, t, c)) ret.push_back(t); return ret; } int main() { cout << fixed << setprecision(1); int testcase = 0; int n = 0; while(cin >> n) { if(n == 0) break; G g; rep(i, n) { D x, y; cin >> x >> y; g.emplace_back(x, y); } cout << ++testcase << " " << area(g) << endl; } return 0; }
#include<stdio.h> #include<algorithm> using namespace std; double ABS(double a){return max(a,-a);} int x[52]; int y[52]; int main(){ int n=0; int a; while(scanf("%d",&a),a){ for(int i=1;i<=a;i++)scanf("%d%d",x+i,y+i); x[a+1]=x[1]; y[a+1]=y[1]; x[0]=x[a]; y[0]=y[a]; double ret=0; for(int i=1;i<=a;i++){ ret+=(x[i+1]-x[i])*(y[i]+y[i+1]); } printf("%d %.1f\n",++n,ABS(ret)/2); } }
#include <iostream> #include <vector> #include <cstdio> #include <complex> #include <utility> #define EPS (1e-10) #define X real() #define Y imag() using namespace std; typedef complex<double> P; typedef pair<P,P> L; typedef vector<P> Poly; double cross(P a, P b){ return a.X*b.Y - a.Y*b.X; } double area(Poly p){ int n = p.size(); double s = 0; for(int i = 0; i < n; ++i){ s -= cross(p[i],p[(i+1)%n])/2; } return s; } int main(){ int n, c = 0; while(cin >> n, n > 0){ ++c; cout << c << " "; Poly p; double x, y; for(int i = 0; i < n; ++i){ cin >> x >> y; p.push_back(P(x,y)); } printf("%.1lf\n",area(p)); } return 0; }
#include <iostream> #include <cstdio> #include <cmath> #include <vector> using namespace std; #define MAX 51 typedef pair<double,double> P; int main(){ int n,t = 1; while(cin >> n,n){ vector<P> v; double ans = 0, x ,y; for(int i = 0 ; i < n ; i++){ cin >> x >> y; v.push_back(P(x,y)); } for(int i = 1; i < n+1 ; i++){ ans += (v[i%n].first-v[i-1].first)*(v[i%n].second+v[i-1].second); } ans /= 2.0; printf("%d %.1f\n" ,t++ ,abs(ans)); } return 0; }
#include<cmath> #include<algorithm> #include<iostream> #include<vector> #include<climits> #include<cfloat> #include<cstdio> #define curr(P, i) P[(i) % P.size()] #define next(P, i) P[(i+1) % P.size()] #define prev(P, i) P[(i+P.size()-1) % P.size()] using namespace std; struct point{ double x, y; }; double areaPol(vector<point> t){ double area=0; for(int i=0;i<t.size();i++){ area+=(curr(t,i).x-next(t,i).x)*(curr(t,i).y+next(t,i).y); } return abs(area)/2.0; } int main(void){ int n,turn=1; point p; vector<point>t; while(cin >> n,n){ t.clear(); for(int i=0;i<n;i++){ cin >> p.x >> p.y; t.push_back(p); } printf("%d %.1f\n",turn++,areaPol(t)); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using uint = unsigned int; using vi = vector<int>; using vb = vector<bool>; using vd = vector<double>; using vl = vector<ll>; using vvi = vector<vi>; using vvb = vector<vb>; using vvd = vector<vd>; using vvl = vector<vl>; #define REP(i,n) for(ll i=0; i<(n); ++i) #define FOR(i,b,n) for(ll i=(b); i<(n); ++i) #define ALL(v) (v).begin(), (v).end() #define TEN(x) ((ll)1e##x) template<typename T> inline string join(const vector<T>& vec, string sep = " ") { stringstream ss; REP(i, vec.size()) ss << vec[i] << ( i+1 == vec.size() ? "" : sep ); return ss.str(); } /////////////// #define EPS (1e-10) #define NEXT(x, i) (x[(i + 1) % x.size()]) template<class T> using CR = const T &; using P = complex<ld>; using G = vector<P>; ld dot(P a, P b) { return real(conj(a)*b); } ld cross(P a, P b) { return imag(conj(a)*b); } ld area2(CR<G> g) { ld s = 0; REP(i, g.size()) s += cross(g[i], NEXT(g, i)); return s; } ////////////// int main() { #ifdef INPUT_FROM_FILE ifstream cin("sample.in"); ofstream cout("sample.out"); #endif cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); ll i = 1; while (true) { ll n; cin >> n; if (n == 0) break; G g; REP(i, n) { ld x, y; cin >> x >> y; g.push_back({ x, y }); } cout << fixed << setprecision(1); cout << i << " " << abs(area2(g)) / 2 << endl; ++i; } return 0; }
#include <bits/stdc++.h> #define FOR(v, a, b) for(int v = (int)(a); v < (int)(b); ++v) #define FORE(v, a, b) for(int v = (int)(a); v <= (int)(b); ++v) #define REP(v, n) FOR(v, 0, n) #define REPE(v, n) FORE(v, 0, n) #define RS resize #define CLR clear #define PB push_back #define ALL(x) (x).begin(), (x).end() using namespace std; void split(string str, char chr, vector< string > *res){ stringstream ss(str); string itm; while(getline(ss, itm, chr)){ (*res).PB(itm); } } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n, x, y, j = 1; double area; vector< complex< int > > p; while(cin >> n, n){ p.CLR(); p.RS(n); REP(i, n){ cin >> x >> y; p[i] = complex< int >(x, y); } area = 0; for(int i = 0; i < n; ++i){ area += (p[i].imag() * p[(i+1)%n].real() - p[i].real() * p[(i+1)%n].imag()); } area /= 2; printf("%d %.1lf\n", j, abs(area)); ++j; } return 0; }
#include<iostream> #include<vector> #include<cstdio> #include<utility> #include<cmath> using namespace std; int main(){ int n, k=1; vector< pair<int,int> > points; while( cin >> n, n ){ points.clear(); for( int i=0; i<n; i++ ){ int x, y; cin >> x >> y; points.push_back( make_pair(x,y) ); } points.push_back( make_pair( points[0].first, points[0].second ) ); double sum=0; for( int i=0; i+1<points.size(); i++ ){ sum += ((points[i].second+points[i+1].second)*(points[i+1].first-points[i].first))/2.0; } printf("%d %.1f\n", k++, fabs(sum) ); } return 0; }
#include <iostream> #include <iomanip> using namespace std; const int MAX_N=50; int k=1; int N; pair<int,int> v[MAX_N+1]; int main(){ while(1){ float ans=0; cin >> N; if(N==0)break; for(int i=0;i<N;i++){ cin >> v[i].first >> v[i].second; } for(int i=1;i<N-1;i++){ ans+=(v[i].first-v[0].first) * (v[i+1].second-v[0].second) - (v[i].second-v[0].second) * (v[i+1].first-v[0].first); } if(ans < 0) ans=-ans; ans*=0.5; cout << fixed << setprecision(1) << k << " " << ans << endl; k++; } }
#include <vector> #include <iostream> #include <complex> #include <cstdio> #define pb push_back #define fs first #define sc second #define sz size() using namespace std; typedef double D; typedef complex<D> P; typedef pair<P, P> L; typedef pair<P, D> C; typedef vector<P> Poly; const D EPS=1e-12; namespace std{ bool operator<(const P &a, const P &b){ return real(a)==real(b)?imag(a)<imag(b):real(a)<real(b); } } P unit(P p){ return p / abs(p);} D dot(P x, P y){return real(conj(x)*y);} D cross(P x, P y){return imag(conj(x)*y);} P rotate(P v, double s){ return P(real(v)*cos(s) - imag(v) * sin(s), real(v)*sin(s) + imag(v) * cos(s)); } D arg(P a, P b, P c){ return acos(dot(b-a, c-a)/(abs(b-a)*abs(c-a)));} D arg(D a, D b, D c){return acos((b*b+c*c-a*a)/(2*b*c));} int ccw(P a, P b, P c){ b -= a; c -= a; if(cross(b, c) > EPS) return 1; if(cross(b, c) < -EPS) return -1; if(dot(b, c) < -EPS) return 2; if(abs(b) < abs(c)) return -2; return 0; } bool para(L a, L b){return abs(cross(a.fs - a.sc, b.fs-b.sc))<EPS;} vector<P> cp_cir_to_cir(C a, C b){ vector<P> v; D s = arg(b.sc, abs(b.fs -a.fs), a.sc); P x = a.sc * unit(b.fs - a.fs); v.pb(a.fs + rotate(x, s)); v.pb(a.fs + rotate(x, -s)); return v; } D area(Poly p){ if(p.sz<3) return 0; D res = cross(p[p.sz-1],p[0]); for(int i=1;i<p.sz;i++) res += cross(p[i-1], p[i]); return res/2; } int main(){ int n; int k=0; while(scanf("%d", &n)){ if(n==0) break; vector<P> v; D x, y; for(int i=0;i<n;i++){ scanf("%lf %lf", &x, &y); v.pb(P(x, y)); } printf("%d %.1lf\n", k+1, -area(v)); k++; } return 0; }
#include <cmath> #include <iomanip> #include <vector> #include <iostream> using namespace std; const double EPS=1e-10; const double INF=1e10; // 点オブジェクト // ベクトルを表すのにも使う struct Point { double x, y; Point(double x=0, double y=0) : x(x), y(y) {} double distance (const Point &o) const { return sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y)); } Point operator+(const Point &o) const { return Point(x+o.x, y+o.y); } Point operator-(const Point &o) const { return Point(x-o.x, y-o.y); } Point operator*(const double m) const { return Point(x*m, y*m); } Point operator/(const double d) const { return Point(x/d, y/d); } // 外積 double cross(const Point &o) const { return x * o.y - y * o.x; } // 内積 double dot(const Point &o) const { return x * o.x + y * o.y; } // ベクトルがx軸となす角 double atan() const { return atan2(y, x); } // ベクトルの長さの二乗 double norm() const { return dot(*this); } }; // 点の進行方向 // 戻り値: // +1: 反時計回り // -1: 時計回り // +2: c, a, bの順に一直線上 // -2: a, b, cの順に一直線上 // 0: a, c, bの順に一直線上 int ccw(Point a, Point b, Point c) { b = b-a, c = c-a; if (b.cross(c) > EPS) return +1; if (b.cross(c) < -EPS) return -1; if (b.dot(c) < 0) return +2; if (b.norm() < c.norm()) return -2; return 0; } // 多角形 struct Polygon { vector<Point> vertex; Polygon() {} Polygon(vector<Point> vertex) : vertex(vertex) {} inline void add_vertex(Point v) { vertex.push_back(v); } Point next(int v) const { return vertex[(v+1) % vertex.size()]; } Point prev(int v) const { return vertex[(v-1+vertex.size()) % vertex.size()]; } double area() const { double ret = 0; for (int i = 0; i < vertex.size(); i++) { ret += vertex[i].cross(next(i)); } return abs(ret) * 0.5; } }; int main() { int curset = 1; int n; while (cin >> n, n != 0) { Polygon polygon; Point pt; for (int i = 0; i < n; i++) { cin >> pt.x >> pt.y; polygon.add_vertex(pt); } cout << setprecision(1); cout << fixed; cout << curset++ << ' ' << polygon.area() << endl; } return 0; }
#include <iostream> using namespace std; float abso(float a) { if(a < 0) return (-1.0f)*a; else return (1.0f)*a; } int main() { int n; int c=1; float out = 0; float x[1000] = {0}; float y[1000] = {0}; float o[1000] = {0}; while( cin >> n , n) { for( int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } for( int i = 1; i < n - 1 ; i++) { float x1 = x[i] - x[0]; float x2 = x[i+1] - x[0]; float y1 = y[i] - y[0]; float y2 = y[i+1] - y[0]; out += x1*y2 - x2*y1; } o[c] = 0.5*abso(out); c++; for( int i = 0; i < 1000; i++) { x[i] = 0; y[i] = 0; } out = 0; } for(int i = 1; i < c ; i++) { printf("%d %.1f\n", i, o[i]); } return 0; }
#include <stdio.h> #include <stack> #include <math.h> using namespace std; struct Point{ double x,y; }; int main(){ int n,count = 1; while(true){ scanf("%d",&n); getchar(); if(n == 0)break; double gaiseki,sum = 0; Point points[n]; for(int i=0; i < n; i++){ scanf("%lf %lf",&points[i].x,&points[i].y); } sum = points[n-1].x*points[0].y - points[n-1].y*points[0].x; for(int i=0; i < n-1; i++){ gaiseki = points[i].x*points[i+1].y - points[i].y*points[i+1].x; sum += gaiseki; } printf("%d %.1lf\n",count,fabs(sum)/2); count++; } return 0; }
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <fstream> #define EPS 1e-10 using namespace std; typedef long long int ll; const double PI=acos(-1.0); double add(double a, double b){ if(abs(a+b)<EPS*(abs(a)+abs(b))) return 0; return a+b; } struct P{ double x, y; P() {} P(double x, double y): x(x), y(y){ } P operator+ (P p){ return P(add(x, p.x), add(y, p.y)); } P operator- (P p){ return P(add(x, -p.x), add(y, -p.y)); } P operator* (double d){ return P(x*d, y*d); } double dot(P p){ return add(x*p.x, y*p.y); } double det(P p){ return add(x*p.y, -y*p.x); } bool operator< (const P& p) const{ if(abs(x-p.x)>EPS){ return x<p.x; }else{ return y<p.y-EPS; } } }; bool on_seg(P p1, P p2, P q){ return (p1-q).det(p2-q)==0 && (p1-q).dot(p2-q)<=0; } P intersection(P p1, P p2, P q1, P q2){ return p1+(p2-p1)*((q2-q1).det(q1-p1) / (q2-q1).det(p2-p1)); } int main() { int c=1; while(1){ int n; scanf("%d", &n); if(n==0) return 0; P p[50]; for(int i=0; i<n; i++){ double x, y; scanf("%lf %lf", &x, &y); p[i]=P(x, y); } double area=0; for(int i=0; i<n-1; i++){ area+=(p[i].det(p[i+1])); } area+=(p[n-1].det(p[0])); area=(-area*0.5); printf("%d %.1lf\n", c, area); c++; } return 0; }
#include <iostream> #include <cstdio> #include <cmath> using namespace std; int n; int x[51], y[51]; int main() { int caseId = 0; while (cin >> n) { if (n == 0) break; caseId++; int i; for (i = 0; i < n; i++) cin >> x[i] >> y[i]; x[n] = x[0]; y[n] = y[0]; int area = 0; for (i = 0; i < n; i++) { area += x[i] * y[i + 1] - y[i] * x[i + 1]; } printf("%d %.1f\n", caseId, abs(area) * 0.5); } return 0; }
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <cstring> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <fstream> #include <complex> #include <stack> #include <queue> using namespace std; typedef long long LL; typedef pair<double,double> P; static const double EPS = 1e-5; #define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i) #define REP(i,n) FOR(i,0,n) int main(void){ int n; int cas = 1; while(cin>>n){ if(n==0) break; vector<P> p; REP(i,n){ double x,y; cin>>x>>y; p.push_back(P(x,y)); } p.push_back(p[0]); double ans = 0; REP(i,p.size()-1){ ans += 0.5*(p[i+1].first-p[i].first)*(p[i].second+p[i+1].second); } printf("%d %.1lf\n",cas++,ans); } return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; #define range(i, a, b) for (int i = a; i < b; ++i) #define rep(i, n) range(i, 0, n) #define pb push_back struct point { double x; double y; }; int main() { int n; int i = 0; cout << fixed; while (cin >> n, n > 0) { ++i; vector<point> P; rep(i, n) { double x, y; cin >> x >> y; point pnt; pnt.x = x; pnt.y = y; P.pb(pnt); } double sum = 0; range(i, 1, n - 1) { sum += (P[i].x - P[0].x) * (P[i + 1].y - P[0].y) - (P[i].y - P[0].y) * (P[i + 1].x - P[0].x); } cout << setprecision(0) << i << ' ' << setprecision(1) << abs(sum / 2) << endl; } }
#include<iostream> #include<cmath> #include<cstdio> using namespace std; #define rep(i, n) for(int i = 0; i < n; ++i) int x[100], y[100]; int main() { int n; for (int ii = 1;; ++ii) { cin >> n; if (n == 0) break; double res = 0; rep (i, n) cin >> x[i] >> y[i]; rep (i, n) res += x[i] * y[(i + 1) % n] - y[i] * x[(i + 1) % n]; printf("%d %.1lf\n", ii, abs(res / 2)); } }
#include<iostream> #include<iomanip> #include<complex> #include<cmath> using namespace std; #define F(I,J,N) for(int I=J;I<N;I++) typedef complex<double> P; //外積 double cross(P a,P b){ return (real(a)*imag(b)-imag(a)*real(b)); } int main(){ int n,x,y; double ans; P *p; int cnt=1; while(cin>>n){ if(n==0) break; ans=0; p=new P[n+1]; F(i,0,n){ cin>>x>>y; p[i]=P(x,y); } p[n]=p[0]; F(i,0,n) ans+=cross(p[i],p[i+1]); cout<<setprecision(1)<<setiosflags(ios::fixed)<<cnt<<" "<<abs(ans/2)<<endl; cnt++; delete []p; } return 0; }
#include<iostream> #include<vector> #include<stdio.h> #include<cmath> using namespace std; int main(){ int n; int k=1; while(cin>>n,n){ vector<pair<int,int> >v; int x,y; while(n--){ cin>>x>>y; v.push_back(make_pair(x,y)); } double s=0; for(int i=0;i<v.size();i++){ pair<int,int>ne=v[(i+1)%v.size()]; s+=0.5*(ne.second*v[i].first-v[i].second*ne.first); } printf("%d %.1f\n",k++,abs(s)); } }
#include<iostream> #include<algorithm> #include <vector> #include<cmath> #include<cstdio> using namespace std; vector<pair<double, double> > v(51); int main(void){ int n; for(int __i = 1;cin >> n, n; __i++){ for(int i = 0; i < n; i++){ double a, b; cin >> a >> b; v[i] = make_pair(a, b); } v[n] = v[0]; double area = 0; for(int i = 0;i < n; i++){ area += v[i].first * v[i + 1].second - v[i + 1].first * v[i].second; } area = fabs(area)/2; printf("%d %.1f\n", __i, area); } return 0; }
#include<complex> #include<cstdio> #include<iostream> #include<vector> using namespace std; typedef complex<double> Point; #define EPS (1e-10) #define EQ(a,b) (abs((a)-(b)) < EPS) typedef vector<Point> Polygon; double cross(const Point &a, const Point &b) { return imag(conj(a)*b); } double area(const Polygon &p) { double A = 0; for(int i=0; i<p.size(); i++) { A += cross( p[i], p[(i+1)%p.size()] ); } return A; } int main() { int n; int count=1; while(true) { cin>>n; if(!n) break; Polygon p; int x,y; for(int i=0; i<n; i++) { cin>>x>>y; Point k(x,y); p.push_back(k); } Polygon s(p.rbegin(),p.rend()); printf("%d %.1lf\n", count, area(s)/2); count++; } }
#include <iostream> #include <cmath> #include <cstdio> using namespace std; struct t{ double x; double y; }; int main(){ int n,i,count=1; struct t v[55]; while(scanf("%d", &n), n!=0){ double ans = 0.0; for(i = 0; i < n; i++){ cin >> v[i].x >> v[i].y; } v[n].x = v[0].x; v[n].y = v[0].y; for(i = 0; i < n; i++){ ans += (v[i].x*v[i+1].y - v[i+1].x*v[i].y); } printf("%d %.1f\n", count++, fabs(ans/2)); } return 0; }
#include<iostream> #include<cstdio> #include<cmath> #include<vector> using namespace std; struct P{ int x,y; }; int main(){ P point[100]; int n; int Nari = 1; double S; while(cin >> n && n){ for(int i=0;i<n;i++)cin >> point[i].x >> point[i].y; point[n].x = point[0].x; point[n].y = point[0].y; double sum=0; for(int i=0;i<n;i++){ sum+=(point[i].x - point[i+1].x)*(point[i].y+point[i+1].y); } printf("%d %.1lf\n",Nari,fabs(sum/2.0)); Nari++; } return 0; }
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> int n; double x[101],y[101]; int main(void){ int cnt=1; while(1){ scanf("%d",&n); if(n==0)break; for(int i=0;i<n;i++){ scanf("%lf %lf",&x[i],&y[i]); } double res=0.0; for(int i=0;i<n;i++){ res+=y[i]*(x[(i+n-1)%n]-x[(i+1)%n])/2.0; } printf("%d %.1f\n",cnt++,fabs(res)); } return 0; }
#include <iostream> #include <cmath> using namespace std; class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator +(Point p) { return Point(x+p.x, y+p.y); } Point operator -(Point p) { return Point(x-p.x, y-p.y); } }; typedef Point Vector; double cross(Vector a, Vector b) { return a.x*b.y-a.y*b.x; } Point p[50]; int n; double calcS() { double s = 0; for(int i = 0; i < n; i++) { if(i+1 == n) s += cross(p[n-1], p[0]); else s += cross(p[i], p[i+1]); } s /= 2.0; return abs(s); } int main() { int tc = 1; while(1) { cin >> n; if(n == 0) break; for(int i = 0; i < n; i++) { cin >> p[i].x >> p[i].y; } printf("%d %.1f\n", tc, calcS()); tc++; } }
#include <algorithm> #include <vector> #include <complex> using namespace std; //--------------------------------------------------------------- using Point = complex<double>; using Polygon = vector<Point>; double dot(const Point& a, const Point& b) { return real(conj(a) * b); } double cross(const Point& a, const Point& b) { return imag(conj(a) * b); } double area(Polygon ps) { double sum = 0; for (int i = 0; i < ps.size(); i++) { sum += cross(ps[i], ps[(i + 1) % ps.size()]); } return abs(sum) / 2; } //--------------------------------------------------------------- #include <iomanip> // cout << fixed << setprecision(1) #include <iostream> int main() { int n, cnt = 0; while (cin >> n, n) { cnt++; vector<Point> ps(n); int x, y; for (int i = 0; i < n; i++) { cin >> x >> y; ps[i] = Point(x, y); } double ans = area(ps); cout << fixed << setprecision(1); cout << cnt << " " << ans << endl; } return 0; }
#include <iostream> #include <cstdio> using namespace std; int cross(int ax, int ay, int bx, int by, int cx, int cy) { int x1 = bx-ax, x2 = cx-ax; int y1 = by-ay, y2 = cy-ay; return x1*y2 - x2*y1; } int main() { int n; int seq = 0; int ax, ay, bx, by, cx, cy; while (1) { cin >> n; if (!n) break; seq++; int area = 0; cin >> ax >> ay >> bx >> by; for (int i = 0; i < n-2; i++) { cin >> cx >> cy; area += cross(ax,ay,bx,by,cx,cy); bx = cx, by = cy; } printf("%d %.1f\n", seq, (double)(area>=0.0 ? area : -area) * 0.5); } return 0; }
#include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(int)(n); ++i) using namespace std; #define X real() #define Y imag() typedef double D; D EPS = 1e-8; typedef complex<D> P; struct L{ P a, b; P vec(){ return b - a; } }; typedef vector<P> Pol; int sig(D a) { return a < -EPS ? -1 : a > EPS ? 1 : 0; } D dot(P a, P b){ return a.X * b.X + a.Y * b.Y; } D cross(P a, P b){ return a.X * b.Y - a.Y * b.X; } D area(Pol pol) { int n = pol.size(); D res = 0; REP(i, n) { res += cross(pol[i], pol[ (i + 1) % n ]); } return abs(res) / 2.0; } int main(){ int n; int t = 0; while(cin >> n && n > 0) { Pol pol(n); REP(i, n) { double x, y; cin >> x >> y; pol[i] = P(x, y); } printf("%d %.1f\n", ++t, area(pol)); } return 0; }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0; i<n; i++) using namespace std; int main(){ int n; vector<pair<int, int> > point; int cnt = 0; while(cin >> n,n){ cnt++; point.resize(n); rep(i,n){ cin >> point[i].first >> point[i].second; } double ans_s = 0; for(int i=0; i<point.size(); i++){ int idx = (i+1)%point.size(); ans_s += 0.5*((point[idx].first-point[i].first) *(point[i].second+point[idx].second)); } cout << cnt << " " << fixed << setprecision(1) << ans_s << endl; } return 0; }
#include <cstdio> #include <iostream> #include <cmath> using namespace std; int main(){ int i,j,n,c=0; double x[50],y[50],a[50],ans; while(1){ cin >> n; if(n == 0) break; ans = 0; for(i=0;i<n;i++) cin >> x[i] >> y[i]; for(i=0;i<n;i++){ ans += (x[i] - x[(i+1)%n]) * (y[i] + y[(i+1)%n]); } ans /= -2; cout << ++c << " "; printf("%.1f\n",ans); } return 0; }
#include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() { int num; int count = 1; while (true) { cin >> num; if (num == 0) break; double area = 0.0; int x1, y1, bx, by, ax, ay; cin >> x1 >> y1; bx = x1; by = y1; for (int i = 1; i < num; i++) { cin >> ax >> ay; area += bx * ay - ax * by; bx = ax; by = ay; } area += bx * y1 - x1 * by; cout << setprecision(1) << fixed; cout << count++ << " " << 0.5 * abs(area) << endl; } return 0; }
#include<iostream> #include<vector> #include<stdio.h> using namespace std; int main(){ int n; double tmp,s; int count; vector<double> px,py; count = 1; while(cin >> n){ if(n ==0){ return 0; } s = 0; px.clear(); py.clear(); for(int i=0;i<n;i++){ cin >> tmp; px.push_back(tmp); cin >> tmp; py.push_back(tmp); } for(int i = 0;i<n-1;i++){ s = s + (px[i] - px[i+1])*(py[i] + py[i+1]); } s = s + (px[n-1] -px[0])*(py[n-1]+py[0]); if(s < 0){s = -s;} printf("%d %.1f\n",count,s/2); count += 1; } }
#include <stdio.h> int main(){ int n; int i; int count = 0; double x[100],y[100]; double ans; scanf("%d",&n); while(n != 0){ count++; for(i = 0; i < n; i++){ scanf("%lf %lf",&x[i],&y[i]); } ans = 0; for(i = 1; i < n-1; i++){ ans += ((y[i] - y[0]) * (x[i + 1] - x[0]) - (y[i + 1] - y[0]) * (x[i] - x[0])) / 2; } printf("%d %.1f\n",count,ans); scanf("%d",&n); } return 0; }
#include <iostream> #include <vector> #include <utility> #include <cstdio> using namespace std; #define X first #define Y second typedef pair<double,double> Pdd; int main() { int n; double x, y; int cnt = 0; double ans; vector<Pdd> v; while(cin>>n, n) { v.clear(); for(int i=0; i<n; i++) { cin>>x>>y; v.push_back(make_pair(x,y)); } ans = 0; for(int i=0; i<n; i++) { ans+=(v[(i+1)%n].X-v[i].X)*(v[(i+1)%n].Y+v[i].Y)/2; } printf("%d %.1f\n", ++cnt, ans); } return 0; }
#include <stdio.h> #include <iostream> #include <vector> #include <list> #include <cmath> #include <fstream> #include <algorithm> #include <string> #include <queue> #include <set> #include <map> #include <complex> #include <iterator> #include <cstdlib> #include <cstring> #include <sstream> using namespace std; #define EPS (1e-10) #define EQ(a,b) (abs((a) - (b)) < EPS) #define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag())) typedef complex<double> P; typedef long long ll; const int MAX_SIZE = 10000; // “àÏ double dot(P a, P b) { return (a.real() * b.real() + a.imag() * b.imag()); } // ŠOÏ double cross(P a, P b) { return (a.real() * b.imag() - a.imag() * b.real()); } // “_c‚ª’¼üabã‚É‚ ‚é‚©‚È‚¢‚© int is_point_on_line(P a, P b, P c) { return EQ( cross(b-a, c-a), 0.0 ); } // 2’¼ü‚Ì’¼s”»’è int is_orthogonal(P a1, P a2, P b1, P b2) { return EQ( dot(a1-a2, b1-b2), 0.0 ); } // 2’¼ü‚Ì•½s”»’è int is_parallel(P a1, P a2, P b1, P b2) { return EQ( cross(a1-a2, b1-b2), 0.0 ); } // “_a,b‚ð’ʂ钼ü‚Æ“_c‚ÌŠÔ‚Ì‹——£ double distance_l_p(P a, P b, P c) { return abs(cross(b-a, c-a)) / abs(b-a); } // “_a,b‚ð’[“_‚Æ‚·‚éü•ª‚Æ“_c‚Ƃ̋——£ double distance_ls_p(P a, P b, P c) { if ( dot(b-a, c-a) < EPS ) return abs(c-a); if ( dot(a-b, c-b) < EPS ) return abs(c-b); return abs(cross(b-a, c-a)) / abs(b-a); } // a1,a2‚ð’[“_‚Æ‚·‚éü•ª‚Æb1,b2‚ð’[“_‚Æ‚·‚éü•ª‚ÌŒð·”»’è int is_intersected_ls(P a1, P a2, P b1, P b2) { return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) && ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS ); } // a1,a2‚ð’[“_‚Æ‚·‚éü•ª‚Æb1,b2‚ð’[“_‚Æ‚·‚éü•ª‚ÌŒð“_ŒvŽZ P intersection_ls(P a1, P a2, P b1, P b2) { P b = b2-b1; double d1 = abs(cross(b, a1-b1)); double d2 = abs(cross(b, a2-b1)); double t = d1 / (d1 + d2); return a1 + (a2-a1) * t; } // a1,a2‚ð’ʂ钼ü‚Æb1,b2‚ð’ʂ钼ü‚ÌŒð·”»’è int is_intersected_l(P a1, P a2, P b1, P b2) { return !EQ( cross(a1-a2, b1-b2), 0.0 ); } // a1,a2‚ð’ʂ钼ü‚Æb1,b2‚ð’ʂ钼ü‚ÌŒð“_ŒvŽZ P intersection_l(P a1, P a2, P b1, P b2) { P a = a2 - a1; P b = b2 - b1; return a1 + a * cross(b, b1-a1) / cross(b, a); } /* ‰~Žü‚Ɛü•ª‚ÌŒð·”»’è */ bool isCircleCrossLine(P a,P b,P c,double r){ double d1 = abs(a-c); double d2 = abs(b-c); if(d1<r&&d2<r){ return false; } double d = distance_ls_p(a,b,c); if(EQ(d,r)||d<r){ return true; } else return false; } // ŽOŠpŒ`‚Ì“à•”‚É“_‚ª‚ ‚é‚©‚Ç‚¤‚© // ŠOÏ‚̐³•‰‚ª‚·‚ׂ睂¶‚È‚ç“à•”‚É“_‚ ‚è bool isInTriangle(P p1,P p2,P p3,P s){ P a=p1-s; P b=p2-s; P c=p3-s; return ((cross(a,b)>0&&cross(b,c)>0&&cross(c,a)>0)||(cross(a,b)<0&&cross(b,c)<0&&cross(c,a)<0)); } // ŽOŠpŒ`‚̖ʐςðÀ•W‚©‚çŒvŽZ double calcAreaOfTriangle(P a,P b,P c){ return abs((b.real()-a.real())*(c.imag()-a.imag()) - (c.real()-a.real())*(b.imag()-a.imag()))/2; } // —^‚¦‚ç‚ꂽ‰~‚͈͓̔à‚É“_‚ª‘¶Ý‚·‚é‚©‚Ç‚¤‚© bool isContainingDot(P c,double r,P a){ if(((c.real()-a.real())*(c.real()-a.real()) +(c.imag()-a.imag())*(c.imag()-a.imag())<r*r) ||EQ((c.real()-a.real())*(c.real()-a.real()) +(c.imag()-a.imag())*(c.imag()-a.imag()),r*r)){ return true; } else return false; } // ‘½ŠpŒ`‚̖ʐόöŽ® double calcPolygonArea(vector<P> p){ double sum=0; for(int i = 0; i < p.size(); i++){ sum+=cross(p[i],p[(i+1)%(p.size())]); } return sum/2; } int main(){ int n; int idx=1; while(cin>>n&&n!=0){ cout<<idx<<" "; double S=0.0; vector<P> v; for(int i = 0; i < n; i++){ int x,y; cin>>x>>y; v.push_back(P(x,y)); } S=calcPolygonArea(v); if(S<0) S=-S; printf("%.1f\n",S); idx++; } return 0; }
#include<complex> #include<vector> #include<cmath> using namespace std; #define curr(P, i) P[i] #define next(P, i) P[(i+1)%P.size()] const double EPS = 1e-8; const double INF = 1e12; typedef complex<double> P; namespace std { bool operator < (const P& a, const P& b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } } double cross(const P& a, const P& b) { return imag(conj(a)*b); } double dot(const P& a, const P& b) { return real(conj(a)*b); } struct L : public vector<P> { L(const P &a, const P &b) { push_back(a); push_back(b); } }; struct C { P p; double r; C(const P &p, double r) : p(p), r(r) { } }; typedef vector<P> G; double area2(const G& P) { double A = 0; for (int i = 0; i < P.size(); ++i) A += cross(curr(P, i), next(P, i)); return A; } int main(){ int n,k=1; double x,y; while(scanf("%d",&n),n){ G g; for(int i=0;i<n;i++)scanf("%lf %lf",&x,&y),g.push_back(P(x,y)); printf("%d %.1f\n",k++,abs(area2(g)/2)); } return 0; }
#include <bits/stdc++.h> using namespace std; struct xy{ int x; int y; }; int main(){ int n; int data=1; while(cin >> n , n){ vector<xy> v(n); for(int i=0;i<n;++i){ cin >> v[i].x >> v[i].y; } double ans=0.; int bx=v[0].x; int by=v[0].y; for(int i=1;i<n-1;i++){ int ta,tb,tc,td; ta=bx-v[i].x; tb=by-v[i].y; tc=bx-v[i+1].x; td=by-v[i+1].y; ans+=ta*td-tc*tb; } cout << data++ << " " << fixed << setprecision(1) << fabs(ans)*0.5 << endl; } return 0; }
#include<cmath> #include<algorithm> #include<iostream> #include<vector> #include<cstdio> #define curr(P, i) P[(i) % P.size()] #define next(P, i) P[(i+1) % P.size()] using namespace std; struct point{ double x, y; }; //http://www004.upp.so-net.ne.jp/s_honma/urawaza/area2.htm double areaPol(vector<point> t){ double area=0; for(int i=0;i<t.size();i++) area+=(curr(t,i).x-next(t,i).x)*(curr(t,i).y+next(t,i).y); return abs(area)/2.0; } int main(void){ int n,turn=1; point p; vector<point>t; while(cin >> n,n){ t.clear(); for(int i=0;i<n;i++){ cin >> p.x >> p.y; t.push_back(p); } printf("%d %.1f\n",turn++,areaPol(t)); } return 0; }
#include <iostream> #include <vector> #include <math.h> using namespace std; #define REP(i, n) for(int i=0; i<n; i++) typedef vector<int> VI; int N, x, y; VI vx, vy; double triangle(int x0, int y0, int x1, int y1, int x2, int y2) { double l0 = sqrt((double)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))); double l1 = sqrt((double)((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1))); double l2 = sqrt((double)((x0 - x2) * (x0 - x2) + (y0 - y2) * (y0 - y2))); double theta = acos((l1*l1 + l2*l2 - l0*l0) / (2.0 * l1 * l2)); return 0.5 * l1 * l2 * sin(theta); } double ccw(int x0, int y0, int x1, int y1, int x2, int y2) { int sgn = (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0); if(sgn < 0) return 1.0; else return -1.0; } int main() { int count = 0; while( 1 ) { count++; cin >> N; if(N==0) break; vx.clear(); vy.clear(); REP(n, N) { cin >> x; cin >> y; vx.push_back(x); vy.push_back(y); } int x0 = vx[0]; int y0 = vy[0]; double S = 0.0; for(int k=1; k<vx.size()-1; k++) { int x1 = vx[k]; int y1 = vy[k]; int x2 = vx[k+1]; int y2 = vy[k+1]; S += ccw(x0, y0, x1, y1, x2, y2) * triangle(x0, y0, x1, y1, x2, y2); } printf("%d %.1f\n", count, S); } }
#include<iostream> #include<cstdio> using namespace std; int main(){ long n,x[51],y[51],s,i,k=1; while(cin>>n){ if(n==0)break; for(i=0;i<n;i++)cin>>x[i]>>y[i]; x[n]=x[0];y[n]=y[0]; for(s=0,i=0;i<n;i++)s+=x[i]*y[i+1]-x[i+1]*y[i]; if(s<0)s=-s; printf("%d %.1f\n",k++,s/2.); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pair<int, int> > vii; #define rrep(i, m, n) for(int (i)=(m); (i)<(n); (i)++) #define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++) #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) #define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--) #define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--) #define rev(i, n) for(int (i)=(n)-1; (i)>=0; (i)--) #define vrep(i, c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; } template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; } const int INF = 1000000000; const ll MOD = 1000000007LL; const double EPS = 1E-12; struct Point : public complex<double> { public: Point() { this->real(0); this->imag(0); } Point(const double& x, const double& y) { this->real(x); this->imag(y); } Point(const complex<double> w) { this->real(w.real()); this->imag(w.imag()); } inline double dot(Point p){ return (conj(*this) * p).real(); } // ?????? inline double det(Point p){ return (conj(*this) * p).imag(); } // ?????? }; namespace std { inline bool operator < (const Point& a, const Point& b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } } typedef vector<Point> Polygon; inline Point currPoint(vector<Point> P, int i){ return P[i]; } inline Point nextPoint(vector<Point> P, int i){ return P[(i+1)%P.size()]; } inline Point diffPoint(vector<Point> P, int i){ return nextPoint(P, i) - currPoint(P, i); } // ?¬?????????¢??????A = 1/2 ?£a ?? b????????¨?????????????????????????????????????????????????????±?????? double AreaOfPolygon(const Polygon& P) { double A = 0.0; for (int i = 0; i < P.size(); ++i) A += currPoint(P, i).det(nextPoint(P, i)); return A; } int n; double x, y; int cnt; int main() { while((cin >> n) && n){ Polygon P; rep(i, n){ cin >> x >> y; P.pb(Point(x, y)); } printf("%d %.1f\n", ++cnt, abs(AreaOfPolygon(P)) / 2.0); } return 0; }
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<cassert> #include<iostream> #include<sstream> #include<string> #include<vector> #include<queue> #include<set> #include<map> #include<utility> #include<numeric> #include<algorithm> #include<bitset> #include<complex> #include<stack> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int,int> pint; typedef vector<string> vstring; typedef vector<pint> vpint; typedef stringstream SS; template<class T> void chmin(T &t, T f) { if (t > f) t = f; } template<class T> void chmax(T &t, T f) { if (t < f) t = f; } #define rep(i,n) for(int i=0;i<(n);++i) #define repn(i,m,n) for(int i=(m);i<(n);++i) #define repd(i,n) for(int i=(n)-1;i>=0;--i) #define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i) #define rep0(i,n) for(i=0;i<(n);++i) #define repn0(i,m,n) for(i=(m);i<(n);++i) #define repd0(i,n) for(i=(n)-1;i>=0;--i) #define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i) #define repc(i,n) for(int i=0;i<=(n);++i) #define repcn(i,m,n) for(int i=(m);i<=(n);++i) #define repcd(i,n) for(int i=(n);i>=0;--i) #define repcnd(i,m,n) for(int i=(n);i>=(m);--i) #define repc0(i,n) for(i=0;i<=(n);++i) #define repcn0(i,m,n) for(i=(m);i<=(n);++i) #define repcd0(i,n) for(i=(n);i>=0;--i) #define repcnd0(i,m,n) for(i=(n);i>=(m);--i) #define all(n) n.begin(),n.end() #define sz(n) ((int)(n).size()) #define IL for(;;) #define MP make_pair #define PB push_back #define X second #define Y first #define p_queue(n) priority_queue<n,vector<n>,greater<n> > #define PUTLINE cout<<"LINE:"<<__LINE__<<endl; const int INF = 2147483647/3; const double EPS = 1e-10; const double PI = acos(-1.0); const int dx[]={1,-1,0,0,1,1,-1,-1,0}; const int dy[]={0,0,1,-1,1,-1,1,-1,0}; int x[100], y[100]; int main() { int n, res, count = 0; IL{ cin >> n; if (n == 0) break; rep (i, n) cin >> x[i] >> y[i]; res = 0; rep (i, n - 1) res += (x[i + 1] - x[i]) * (y[i + 1] + y[i]); res += (x[0] - x[n - 1]) * (y[0] + y[n - 1]); res = abs(res); printf("%d %.1f\n", ++count, (double)res / 2); } return 0; }
#include <cmath> #include <iostream> #include <iomanip> #include <algorithm> using namespace std; const double kEps = 1e-10; const double kInf = 1e15; int dcmp(double x) { if (fabs(x) < kEps) return 0; return x < 0 ? -1 : 1; } struct Vector { Vector() {} Vector(double x, double y): x(x), y(y) {} // Vector(const Point & p1, const Point & p2): x(p2.x - p1.x), y(p2.y - p1.y) {} Vector(const Vector & v): x(v.x), y(v.y) {}; double x, y; double Norm() const { return hypot(x, y); } double NormSquared() const { return x * x + y * y; } Vector Normalize() const { return *this / this->Norm(); } Vector operator-() const { return Vector(-x, -y); } Vector operator+(const Vector & rhs) const { return Vector(x + rhs.x, y + rhs.y); } Vector operator-(const Vector & rhs) const { return *this + (-rhs); } Vector operator*(const double rhs) const { return Vector(rhs * x, rhs * y); } Vector operator/(const double rhs) const { return *this * (1.0 / rhs); } double Dot(const Vector & rhs) const { return x * rhs.x + y * rhs.y; } double Cross(const Vector & rhs) const { return x * rhs.y - y * rhs.x; } bool operator==(const Vector & rhs) const { return dcmp(x - rhs.x) == 0 && dcmp(y - rhs.y) == 0; } bool operator<(const Vector & rhs) const { return dcmp(x - rhs.x) < 0 || (dcmp(x - rhs.x) == 0 && dcmp(y - rhs.y) < 0); } }; struct Point { Point() {} Point(double x, double y): x(x), y(y) {} Point(const Point & p): x(p.x), y(p.y) {}; double x, y; Point operator-() { return Point(-x, -y); } Point operator+(const Vector & rhs) const { return Point(x + rhs.x, y + rhs.y); } Point operator-(const Vector & rhs) const { return *this + (-rhs); } bool operator==(const Point & rhs) const { return dcmp(x - rhs.x) == 0 && dcmp(y - rhs.y) == 0; } bool operator<(const Point & rhs) const { return dcmp(x - rhs.x) < 0 || (dcmp(x - rhs.x) == 0 && dcmp(y - rhs.y) < 0); } }; struct Line { Line() {} Line(const Point & p1, const Point & p2): p1(p1), p2(p2) { a = p2.y - p1.y; b = p1.x - p2.x; c = (p2.x - p1.x) * p1.y + (p1.y - p2.y) * p1.x; if (dcmp(p2.x - p1.x) == 0) { k = kInf; } else { k = (p2.y - p1.y) / (p2.x - p1.x); } } Line(double x1, double y1, double x2, double y2): p1(x1, y1), p2(x2, y2) { a = y2 - y1; b = x1 - x2; c = (p2.x - p1.x) * p1.y + (p1.y - p2.y) * p1.x; if (dcmp(x2 - x1) == 0) { k = kInf; } else { k = (y2 - y1) / (x2 - x1); } } Line(const Line & l); Point p1, p2; double a, b, c; double k; }; ostream & operator<<(ostream & os, const Point & p) { os << p.x << " " << p.y; return os; } ostream & operator<<(ostream & os, const Vector & v) { os << v.x << " " << v.y; return os; } ostream & operator<<(ostream & os, const Line & l) { os << l.p1.x << " " << l.p1.y << " " << l.p2.x << " " << l.p2.y; return os; } double Distance(const Point & p1, const Point & p2) { return hypot(p2.x - p1.x, p2.y - p1.y); } // minus: left, plus: right, 0: colinear int Direction(const Point & p0, const Point & p1, const Point & p2) { Vector v1(p1.x - p0.x, p1.y - p0.y); Vector v2(p2.x - p0.x, p2.y - p0.y); return v2.Cross(v1); } Vector Perpendicular(const Point & p, const Line & l) { Vector v0(p.x - l.p1.x, p.y - l.p1.y); Vector v(l.p2.x - l.p1.x, l.p2.y - l.p1.y); auto perpendicular = v * (v.Dot(v0) / v.NormSquared()) - v0; return perpendicular; } int main(int argc, char const *argv[]) { auto count = 0; while (1) { int n; double x0, y0, x1, y1; double area = 0.0; cin >> n; if (n == 0) { break; } cin >> x0 >> y0; cin >> x1 >> y1; Point p0(x0, y0); Point p1(x1, y1); for (unsigned i = 0; i < n - 2; ++i) { double x2, y2; cin >> x2 >> y2; Point p2(x2, y2); auto area_triangle = Distance(p1, p2) * Perpendicular(p0, Line(p1, p2)).Norm() / 2; if (Direction(p0, p1, p2) < 0) { area_triangle *= -1; } area += area_triangle; cout << fixed << setprecision(1); p1 = p2; } cout << ++count << " " << abs(area) << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); using ll = long long; using ull = unsigned long long; const int inf = 2e9; const ll INF = 2e18; const ll MOD = 1e9+7; typedef pair<int,int> P; #define REP(i,n) for (int i = 0; i < (n); i++) #define sz(s) (s).size() #define pb push_back #define fi first #define se second int main(){ ios::sync_with_stdio(false); cin.tie(0); std::cout << fixed << setprecision(1); int n; int id = 0; while (cin >> n,n) { double x[55], y[55]; double area = 0; REP(i, n){ cin >> x[i] >> y[i]; } REP(i, n){ area += (x[i] - x[(i + 1) % n]) * (y[i] + y[(i + 1) % n]); } std::cout << ++id << ' ' << abs(area)/2 << std::endl; } return 0; }
#include<stdio.h> struct V{double x,y;}v[50],a,b; V operator-(V a,V b){V c={a.x-b.x,a.y-b.y};return c;} int main() { int n,i,c=0; double s; while(scanf("%d",&n),n) { for(s=i=0;i<n;++i)scanf("%lf%lf",&v[i].x,&v[i].y); for(i=2;i<n;++i) { a=v[i]-v[0],b=v[i-1]-v[0]; s+=(a.x*b.y-a.y*b.x)/2; } printf("%d %.1f\n",++c,s); } return 0; }
#include <iostream> #include <sstream> #include <iomanip> #include <iostream> #include <sstream> #include <iomanip> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <algorithm> #include <climits> using namespace std; void solve(vector<pair<int,int> > vertex) { int n = vertex.size(); int answer = vertex[0].first*vertex[n-1].second - vertex[0].second*vertex[n-1].first; for(int i=0; i<n-1; ++i) answer += vertex[i+1].first*vertex[i].second - vertex[i+1].second*vertex[i].first; cout << (answer/2) << '.'; if(answer % 2 == 0) cout << '0'; else cout << '5'; cout << endl; } int main() { int number = 0; for(;;){ int n; cin >> n; if(n == 0) break; vector<pair<int,int> > vertex(n); for(int i=0; i<n; ++i) cin >> vertex[i].first >> vertex[i].second; cout << (++number) << ' '; solve(vertex); } return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <map> #include <cmath> #include <iomanip> #include <complex> using namespace std; #define REP(i,n) for (int i=0;i<(n);++i) #define rep(i,a,b) for(int i=a;i<(b);++i) template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;} template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;} using ll = long long; constexpr long long INF = 1LL << 62; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-10; using Point = complex<double>; using Line = pair<Point, Point>; using Polygon = vector<Point>; bool compare(const Point &a, const Point &b) { // x ascending order if(a.real() != b.real()) return a.real() < b.real(); return a.imag() < b.imag(); }; double dot(Point p, Point q) { return (conj(p) * q).real(); } double cross(Point p, Point q) { return (conj(p) * q).imag(); } double area(Polygon &ps) { double res = 0.0; for(int i = 0; i < (int)ps.size(); ++i) res += cross(ps[i], ps[(i+1)%(int)ps.size()]); return abs(res) / 2.0; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(1); int n, cnt = 1; while(true) { cin >> n; if(n == 0) break; double x,y; Polygon ps; for(int i=0; i < n; ++i) { cin >> x >> y; ps.emplace_back(x, y); } cout << cnt << " " << area(ps) << '\n'; ++cnt; } return 0; }
#include <iostream> #include <stdio.h> using namespace std; int main(){ int n, x[51], y[51], c = 1; double pori; while(cin >> n, n != 0){ pori = 0; for(int i = 0; i < n; i++){ cin >> x[i] >> y[i]; } x[n] = x[0]; y[n] = y[0]; for(int i = 0; i < n; i++){ pori += (double)(y[i] + y[i+1]) * (-x[i] + x[i+1]) / 2.0; } printf("%d %.1f\n", c, pori); c++; } return 0; }
#include <iostream> #include <stdio.h> #include <complex> #include <cmath> #include <iomanip> using namespace std; typedef complex<double> xy_t; double cross_product(xy_t a, xy_t b); xy_t P[110]; int main() { double x1,y1,x2,y2; double xin,yin; double sum = 0; int M =0; int count = 0; while(true) { int N = 0; double sum = 0; cin >> M; if(M == 0) break; cin >> xin >> yin; for(int i=0;i<M-2;i++) { cin >> x1 >> y1; //cout << x1 << " " << y1 << endl; if(N == 0) { x2 = x1; y2 = y1; cin >> x1 >> y1; N++; //cout << x1 << " " << y1 << endl; } xy_t A(x1-xin,y1-yin); xy_t B(x2-xin,y2-yin); //cout << cross_product(A,B) << endl; sum += cross_product(A,B)/2; x2 = x1; y2 = y1; N++; } count++; cout << count << " "; cout << fixed << setprecision(1) << sum << endl; } } double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }
#include <bits/stdc++.h> using namespace std; int main() { for(int c=1;;c++) { int n; cin >> n; if(!n) return 0; int x[55] = {}, y[55] = {}; for(int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } x[n] = x[0], y[n] = y[0]; double area = 0; for(int i = 0; i < n; i++) { area += .5 * ( x[i]*y[i+1] - x[i+1]*y[i] ); } area = abs(area); printf("%d %0.1lf\n",c,area); } }
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #define loop(n, i) for(int i=0;i<n;i++) #define loop_from_to(from, to, i) for(int i=from;i<=to;i++) #define repeat(n) for(int i__=0;i__<n;i__++) #define multi_cin(n, array) loop(n,i){cin>>array[i];} #define assign_if_smaller(var, val) if(var>val)var=val; #define assign_if_larger(var, val) if(var<val)var=val; #define each(itr, c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++) #define r_each(itr, c) for(__typeof((c).rbegin()) itr=(c).rbegin(); itr!=(c).rend(); itr++) using namespace std; double calc(int x1,int y1,int x2,int y2) { return (double)(x2-x1)*(y1+y2)/2; } int main(int argc, char const* argv[]) { int count=0; while (true) { int n;cin>>n; if(!n) break; int px,py;cin>>px>>py; int xzero=px,yzero=py; double area=0; n--; while(n--) { int x,y;cin>>x>>y; area+=calc(px,py,x,y); px=x;py=y; } area+=calc(px,py,xzero,yzero); cout<<++count<<" "; cout<<fixed<<setprecision(1)<<area<<endl; } return 0; }
#include<cstdio> #include<cstdlib> #include<math.h> #include<iostream> using namespace std; struct point{ double x,y; }; double tri(point p,point q){ return (p.x*q.y-p.y*q.x); } int main(){ point *p; double ans; int i,j=1,n; while(cin>>n){ if(n==0) break; p=new point[n+1]; for(i=0;i<n;i++) cin>>p[i].x>>p[i].y; p[n]=p[0]; ans=0; for(i=0;i<n;i++) ans+=tri(p[i],p[i+1]); printf("%d %.1f\n",j++,fabs(ans/2)); } return 0; }
#include <iostream> #include <utility> using namespace std; typedef pair<double,double> Pa; int main() { int n; for(int k = 1; k > 0; k++){ cin >> n; if(n == 0){ break; } Pa pr[51]; for(int i = 0; i < n; i++){ cin >> pr[i].first >> pr[i].second; } pr[n] = pr[0]; double s = 0; for(int i = 0; i < n; i++){ s += ((pr[i].first+pr[i+1].first)*(pr[i].second-pr[i+1].second))/2.0; } printf("%d %.1f\n", k, s); } return 0; }
#include <cstdio> #include <iostream> #include <complex> #include <vector> using namespace std; typedef complex<double> point; double cross(const point& a, const point& b) { return imag(conj(a)*b); } typedef vector<point> polygon; double area2(const polygon& P) { double A = 0; for (int i = 0; i < P.size(); ++i) A += cross(P[i], P[(i + 1) % P.size()]); return A; } int main() { int n; int idx = 1; while (cin >> n, n) { polygon pol(n); for (auto& p : pol) { int x, y; cin >> x >> y; p = point(x, y); } pol = polygon(pol.rbegin(), pol.rend()); double a = area2(pol); printf("%d %.1lf\n",idx, a / 2); idx++; } return 0; }
#include <cmath> #include <vector> #include <iostream> #include <algorithm> using namespace std; // ------ Classes ------ // class Point { public: long double px, py; Point() : px(0), py(0) {}; Point(long double px_, long double py_) : px(px_), py(py_) {}; friend bool operator==(const Point& p1, const Point& p2) { return p1.px == p2.px && p1.py == p2.py; } friend bool operator!=(const Point& p1, const Point& p2) { return p1.px != p2.px || p1.py != p2.py; } friend bool operator<(const Point& p1, const Point& p2) { return p1.px < p2.px ? true : (p1.px == p2.px && p1.py < p2.py); } friend bool operator>(const Point& p1, const Point& p2) { return p1.px > p2.px ? true : (p1.px == p2.px && p1.py > p2.py); } friend bool operator<=(const Point& p1, const Point& p2) { return !(p1 > p2); } friend bool operator>=(const Point& p1, const Point& p2) { return !(p1 < p2); } friend Point operator+(const Point& p1, const Point& p2) { return Point(p1.px + p2.px, p1.py + p2.py); } friend Point operator-(const Point& p1, const Point& p2) { return Point(p1.px - p2.px, p1.py - p2.py); } friend Point operator*(const Point& p1, long double d) { return Point(p1.px * d, p1.py + d); } friend Point operator*(long double d, const Point& p1) { return p1 * d; } friend Point operator/(const Point& p1, long double d) { return Point(p1.px / d, p1.py / d); } Point& operator+=(const Point& p1) { px += p1.px; py += p1.py; return *this; } Point& operator-=(const Point& p1) { px -= p1.px; py -= p1.py; return *this; } Point& operator*=(long double d) { px *= d; py *= d; return *this; } Point& operator/=(long double d) { px /= d; py /= d; return *this; } }; // ------ Functions ------ // long double norm(const Point& a) { return a.px * a.px + a.py * a.py; } long double abs(const Point& a) { return sqrtl(norm(a)); } long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; } long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; } long double area(vector<Point> v) { long double ret = 0.0L; for (int i = 0; i < v.size(); i++) ret += crs(v[i], v[(i + 1) % v.size()]); return ret / 2; } // ------ Main ------ // int n, c; vector<Point> v; int main() { while(scanf("%d", &n), n) { v.resize(n); for(int i = 0; i < n; i++) cin >> v[i].px >> v[i].py; printf("%d %.1Lf\n", ++c, abs(area(v))); } }
#include<iostream> #include<vector> #include<cstdio> #include<string> #include<algorithm> #include<numeric> #include<map> #include<math.h> using namespace::std; int main(void) { int counter = 1; int n; while(cin >> n , n != 0 ) { vector< pair<double,double> > vertex(n); double sum = 0.0; for(int i = 0; i < n; i++) { cin >> vertex[i].first >> vertex[i].second; } for(int i = 0; i < vertex.size(); i++) { if( i == vertex.size() - 1 ) { sum += 0.5 * ( (vertex[i].first * vertex[0].second) - (vertex[i].second * vertex[0].first) ); } else { sum += 0.5 * ( (vertex[i].first * vertex[i+1].second) - (vertex[i].second * vertex[i+1].first) ); } } printf("%d %.1f\n", counter , fabs(sum)); counter++; } return 0; }
#include <stdio.h> int main(void) { int now = 0; while( 1 ) { int n, i, j; double ans = 0; scanf("%d", &n); if(!n) break; ++now; int ax[n], ay[n]; for(i = 0; i < n; ++i) scanf("%d%d", &ax[i], &ay[i]); for(i = 1; i < n; ++i) ax[i] -= ax[0], ay[i] -= ay[0]; for(i = 2; i < n; ++i) { ans += ax[i] * ay[i - 1] - ay[i] * ax[i - 1]; } printf("%d %.1f\n", now, ans / 2); } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,t=1; while(cin>>n,n){ double a[n][2],p=0; for(int i=0;i<n;i++) cin>>a[i][0]>>a[i][1]; for(int i=0;i<n;i++) p-=((a[i][0]-a[(i+1)%n][0])*(a[i][1]+a[(i+1)%n][1]))/2; printf("%d %.1f\n",t++,p); } }
#include <iostream> #include <vector> #include <cmath> #include <cstdio> using namespace std; /* double area(double x1,double y1, double x2,double y2, double x3,double y3){ double vx1 = x2-x1; double vy1 = y2-y1; double vx2 = x3-x1; double vy2 = y3-y1; return (abs(vx1*vy2)+abs(vy1*vx2))/2.0; }*/ int main(){ int count=0; while(true){ ++count; int n; double ans = 0.0; vector<double> vx; vector<double> vy; std::cin >> n; if(n==0)return 0; for(int i=0;i<n;i++){ double x,y; cin >> x >> y; vx.push_back(x); vy.push_back(y); } for(int i =0;i<vx.size();i++){ if(i==vx.size()-1){ ans+=(vx[i]-vx[0])*(vy[i]+vy[0]); break; } ans+=(vx[i]-vx[i+1])*(vy[i]+vy[i+1]); } printf("%d %.1f\n",count,abs(ans/2)); } return 0; }
#include <iostream> #include <iomanip> #include <stdio.h> using namespace std; int main(){ int n,ni=1; double x[51],y[51]; while(cin>>n && n){ double s=0; for(int i=0;i<n;i++) cin>>x[i]>>y[i]; x[n]=x[0];y[n]=y[0]; for(int i=0;i<n;i++) s += (x[i]*y[i+1] - x[i+1]*y[i]); if(s<0) s*=-1; printf("%d %.1f\n",ni,s/2.0); ni++; } return 0; }
#include <iostream> #include <cstdio> using namespace std; int main() { int n, c = 1; while (scanf(" %d ", &n) == 1) { if (n == 0) {break;} int x, y, px, py; double S = 0.0; scanf("%d %d ", &px, &py); int x0 = px, y0 = py; for (int i = 1; i < n; i++) { scanf("%d %d ", &x, &y); S += (py + y) * (x - px); px = x, py = y; } S += (y + y0) * (x0 - x); printf("%d %.1lf\n", c++, S / 2); } return 0; }
#include <iostream> #include <vector> #include <fstream> #include <algorithm> #include <iomanip> #include <map> #include <queue> #include <stack> #include <set> #include <iterator> #include <sstream> #include <cstdio> #include <cstdlib> #include <cmath> using namespace std; struct Point { double x; double y; Point(){} Point(double a,double b):x(a),y(b){} }; struct Segment { Point p1; Point p2; Segment(){} Segment(Point a,Point b):p1(a),p2(b){} }; double longueur(Segment s) { return sqrt((s.p1.x-s.p2.x)*(s.p1.x-s.p2.x) + (s.p1.y-s.p2.y)*(s.p1.y-s.p2.y)); } double calculateArea(Segment s1,Segment s2,Segment s3) { double a = longueur(s1), b = longueur(s2), c = longueur(s3); double s = (a+b+c)/2.; return sqrt(s*(s-a)*(s-b)*(s-c)); } double ProductVect(Point p1,Point p2,Point p3) { return (p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y); } int main() { ios_base::sync_with_stdio(false); int nb_points; int cas = 1; while(cin>>nb_points) { if(nb_points == 0) break; cout<<cas<<" "; cas++; vector<Point> points(nb_points); for(int c=0;c<nb_points;c++) { cin>>points[c].x>>points[c].y; } double res = 0; int deb = 0; for(int c=0;c<nb_points;c++) { res+=(points[c].x+points[(c+1)%nb_points].x)*(points[(c)].y-points[(c+1)%nb_points].y); } cout<<fixed<<setprecision(1)<<max(res,-res)/2.<<endl; } }
#include <iostream> #include <algorithm> #include <cctype> #include <cstdio> #include <math.h> using namespace std; int main(){ int m=0; while(1){ m++; int n; double x[51],y[51]; cin>>n; if(n==0)return 0; for(int i=0;i<n;i++){ cin>>x[i]>>y[i]; } double s=x[0]*y[n-1]-x[n-1]*y[0]; for(int i=0;i<n-1;i++){ s+=x[i+1]*y[i]-x[i]*y[i+1]; } printf("%d %.1f\n",m,s/2); } }
#include <cstdio> #include <cmath> using namespace std; int x[51], y[51]; int main() { int n, k=1; while (scanf("%d", &n), n) { for (int i=0; i<n; ++i) scanf("%d%d", x+i, y+i); double res = 0; for (int i=1; i<n-1; ++i) { double ax = x[0]-x[i]; double bx = x[0]-x[i+1]; double ay = y[0]-y[i]; double by = y[0]-y[i+1]; res += bx * ay - ax * by; } printf("%d %.1f\n", k++, res/2); } return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <cfloat> #include <ctime> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #include <stack> #include <queue> #include <numeric> #include <list> using namespace std; #ifdef _MSC_VER #define __typeof__ decltype template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; } #endif #define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it) #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define popcount __builtin_popcount #define CLEAR(arr, val) memset(arr, val, sizeof(arr)) #define rep(i, n) for (int i = 0; i < n; ++i) template <class T> void max_swap(T& a, const T& b) { a = max(a, b); } template <class T> void min_swap(T& a, const T& b) { a = min(a, b); } typedef long long ll; typedef pair<int, int> pint; const double PI = acos(-1.0); const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { 1, 0, -1, 0 }; int main() { int n, x[64], y[64]; for (int T = 1; (scanf("%d", &n), n); ++T) { rep (i, n) scanf("%d%d", x + i, y + i); double res = 0; rep (i, n) res += x[i] * y[(i - 1 + n) % n] - y[i] * x[(i - 1 + n) % n]; res /= 2; printf("%d %.1f\n", T, res); } }
#include<bits/stdc++.h> using namespace std; #define L long long #define mx 100001 int main() { L n,cs=1; while(scanf("%lld",&n)&&n){ double x,y,x1,y1,x2,y2,area=0; scanf("%lf %lf",&x,&y);x1=x;y1=y; scanf("%lf %lf",&x2,&y2); area+=(((y1+y2)/2.0)*(x2-x1));x1=x2;y1=y2; for(L i=2;i<n;i++){ scanf("%lf %lf",&x2,&y2); area+=(((y1+y2)/2.0)*(x2-x1)); x1=x2;y1=y2; } x2=x;y2=y; area+=(((y1+y2)/2.0)*(x2-x1)); printf("%lld %.1f\n",cs++,area); } return 0; }
#include <cstdio> #include <complex> #include <cmath> #include <vector> using namespace std; typedef complex<double> xy_t; double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); } int main() { int id = 1; while (1) { int n; double x, y; double s = 0; scanf("%d", &n); if (n == 0) return 0; vector<xy_t> vertex; for (int i = 0; i < n; i++) { scanf("%lf %lf", &x, &y); vertex.push_back(xy_t(x, y)); } for (int i = 1; i < vertex.size() - 1; i++) { s += cross_product(vertex[i + 1] - vertex[0], vertex[i] - vertex[0]) / 2; } printf("%d %.1f\n", id, s); id++; } }
#include <stdio.h> typedef struct{ double x,y; }point; int main(){ int n,t=0; point p[50]; while(1){ scanf("%d",&n); double s=0; if(n==0) return 0; t++; for(int i=0;i<n;i++) scanf("%lf %lf",&p[i].x,&p[i].y); for(int i=1;i<n-1;i++){ s+=(p[0].x*(p[i].y-p[i+1].y)+p[i].x*(p[i+1].y-p[0].y)+p[i+1].x*(p[0].y-p[i].y))/2; } printf("%d %.1f\n",t,-s); } }
#include<iostream> #include<algorithm> #include<cmath> #include<cstdlib> #include<cstdio> #include<vector> using namespace std; #define EPS (1e-10) #define equals(a,b) (fabs((a)-(b)) < EPS) #define curr(P, i) P[(i) % P.size()] #define next(P, i) P[(i+1) % P.size()] #define prev(P, i) P[(i+P.size()-1) % P.size()] typedef pair<int,int> P; class Point{ public: double x,y; Point(double x = 0, double y = 0): x(x),y(y){}; Point operator + (Point p) {return Point(x+p.x,y+p.y);} Point operator - (Point p) {return Point(x-p.x,y-p.y);} Point operator * (double a) {return Point(a*x,a*y);} double own_dot(){return x*x+y*y;}; double abs(){return sqrt(own_dot());} bool operator < (const Point &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator == (const Point &p) const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; } }; // 内積 double dot(Point a, Point b){ return a.x*b.x+a.y*b.y; } // 外積 double cross(Point a, Point b){ return a.x*b.y-a.y*b.x; } //多角形の面積 double area(vector<Point> P) { double A = 0; for (int i = 0; i < P.size(); i++) A += cross(curr(P, i), next(P, i)); return abs(A/2); } using namespace std; int main(){ int rev = 0; int n; while(cin >> n && n){ vector<Point> V; rev++; while(n--){ Point p; cin >> p.x >> p.y; V.push_back(p); } printf("%d %.1f\n",rev,area(V)); } return 0; }