text
stringlengths 49
983k
|
|---|
#include <iostream>
struct Vec {
double x;
double y;
double operator*(Vec& vec)
{
return (x * vec.y - y * vec.x);
}
};
int sgn(double x);
int main()
{
double x1, y1, x2, y2, x3, y3, x4, y4;
char ch;
while (std::cin >> x1 >> ch >> y1 >> ch >> x2 >> ch >> y2 >> ch
>> x3 >> ch >> y3 >> ch >> x4 >> ch >> y4) {
Vec vec12{x2 - x1, y2 - y1};
Vec vec23{x3 - x2, y3 - y2};
Vec vec34{x4 - x3, y4 - y3};
Vec vec41{x1 - x4, y1 - y4};
double cross01 = vec12 * vec23;
double cross02 = vec23 * vec34;
double cross03 = vec34 * vec41;
double cross04 = vec41 * vec12;
int judge = sgn(cross01) + sgn(cross02) + sgn(cross03) + sgn(cross04);
if (judge == 1 + 1 + 1 + 1 || judge == -1 - 1 - 1 - 1) {
std::cout << "YES" << std::endl;
} else {
std::cout << "NO" << std::endl;
}
}
return 0;
}
int sgn(double x)
{
return ((x >= 0)? 1: (-1));
}
|
#include <iostream>
#include <complex>
#include <cstdio>
using namespace std;
int main(){
float xa, ya, xb, yb, xc, yc, xd, yd;
while(scanf("%f,%f,%f,%f,%f,%f,%f,%f", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF){
float x[4] = {xa,xb,xc,xd};
float y[4] = {ya,yb,yc,yd};
float s[4];
bool allp = true, alln = true;
for(int i = 0; i < 4; ++i){
s[i] = (x[(i+1)%4] - x[i]) * (y[(i+2)%4] - y[(i+1)%4]) - (x[(i+2)%4] - x[(i+1)%4]) * (y[(i+1)%4] - y[i]);
}
for(int i = 0; i < 4; ++i){
if(s[i] < 0){
allp = false;
break;
}
}
for(int i = 0; i < 4; ++i){
if(s[i] > 0){
alln = false;
break;
}
}
if(allp || alln){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
// A[x,y]、B[x,y]を通る直線とC[x,y]、D[x,y]を結ぶ線分の交差判定を返す。
// 「((ax - bx)*(cy - ay)+(ay - by)*(ax - cx))*((ax - bx)*(dy - ay)+(ay - by)*(ax - dx))」
bool cross(double* a, double* b, double* c, double* d) {
return ((a[0]-b[0])*(c[1]-a[1])+(a[1]-b[1])*(a[0]-c[0]))*((a[0]-b[0])*(d[1]-a[1])+(a[1]-b[1])*(a[0]-d[0])) > 0.0;
}
int main() {
// 四角形ABCDの対角線ACとBDの線分が交差するか否かで判定可能である。
// 線分同士を直接比較するのは難しいため、片方を直線とみなした上で、
// 「直線と線分の交差判定」をする事で可能となる。
double pos[4][2];
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
&pos[0][0], &pos[0][1], &pos[1][0], &pos[1][1], &pos[2][0], &pos[2][1], &pos[3][0], &pos[3][1])) {
cout << (cross(pos[0],pos[1],pos[2],pos[3]) && cross(pos[2],pos[3],pos[0],pos[1]) ? "YES" : "NO") << endl;
}
return 0;
}
|
#include <stdio.h>
int
main(void)
{
auto deg = [](double ax, double ay, double bx, double by,
double cx, double cy) -> double {
double abx = bx - ax;
double aby = by - ay;
double acx = cx - ax;
double acy = cy - ay;
return (abx * acy -acx * aby);
};
char line[80];
double xa, ya, xb, yb, xc, yc, xd, yd;
while (true) {
if (fgets(line, sizeof line, stdin) == NULL) {
break;
}
if (sscanf(line, "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,",
&xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != 8) {
break;
}
double d0 = deg(xa, ya, xb, yb, xd, yd);
double d1 = deg(xb, yb, xc, yc, xa, ya);
double d2 = deg(xc, yc, xd, yd, xb, yb);
double d3 = deg(xd, yd, xa, ya, xc, yc);
if ((d0 < 0 && d1 < 0 && d2 < 0 && d3 < 0) ||
(d0 > 0 && d1 > 0 && d2 > 0 && d3 > 0)) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main()
{
double x[4], y[4];
char dummy;
while ( cin >> x[0] >> dummy >> y[0] >> dummy >> x[1] >> dummy >> y[1] >> dummy >> x[2] >> dummy >> y[2] >> dummy >> x[3] >> dummy >> y[3] ) {
bool isClockwise;
if ( x[0] != x[1] ) {
isClockwise = ((y[2] - y[0]) * (x[1] - x[0]) < (y[1] - y[0]) * (x[2] - x[0]));
}
//else if ( x[0] > x[1] ) {
// isClockwise = ((y[2] - y[0]) * (x[1] - x[0]) > (y[1] - y[0]) * (x[2] - x[0]));
//}
else {
isClockwise = ((x[2] > x[1]) == (y[1] > y[0]));
}
//cout << "isClockwise = " << isClockwise << endl;
bool isConvex = true;
for (int i=1; i<4; i++) {
if ( x[i] != x[(i+1)%4] ) {
if ( ((y[(i+2)%4] - y[i]) * (x[(i+1)%4] - x[i]) < (y[(i+1)%4] - y[i]) * (x[(i+2)%4] - x[i])) != isClockwise ) { isConvex = false; break; }
}
//else if ( x[i] > x[(i+1)%4] ) {
// if ( ((y[(i+2)%4] - y[i]) * (x[(i+1)%4] - x[i]) > (y[(i+1)%4] - y[i]) * (x[(i+2)%4] - x[i])) != isClockwise ) { isConvex = false; break; }
//}
else {
if ( ( (x[(i+2)%4] > x[(i+1)%4]) == (y[(i+1)%4] > y[i]) ) != isClockwise ) { isConvex = false; break; }
}
//cout << i << endl;
}
if (isConvex) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
|
#include <iostream>
#include <complex>
#include <cstdio>
using namespace std;
#define EPS 1e-7
typedef complex<double> P;
#define X real()
#define Y imag()
double cross(P a,P b){ return (a.X*b.Y)-(a.Y*b.X); }
int isIntersected(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;
}
int main()
{
double a,b,c,d,e,f,g,h;
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a,&b,&c,&d,&e,&f,&g,&h))
{
P aa(a,b), bb(c,d), cc(e,f), dd(g,h);
cout<<( isIntersected(aa,cc,bb,dd)>0.0 || isIntersected(bb,dd,aa,cc)>0.0 ? "YES" : "NO" )<<endl;
}
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
double line(double x,double x1,double y1,double x2,double y2){
return (y1-y2)/(x1-x2)*(x-x1)+y1;
}
int main(){
double x1,x2,y1,y2,x3,y3,x4,y4;
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF){
if((line(x2,x1,y1,x3,y3)-y2)*(line(x4,x1,y1,x3,y3)-y4)>0 || (line(x1,x2,y2,x4,y4)-y1)*(line(x3,x2,y2,x4,y4)-y3)>0){
cout<<"NO"<<endl;
}else{
cout<<"YES"<<endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main()
{
while(true){
double xa, ya, xb, yb, xc, yc, xd, yd;
if(!(cin>>xa)) break;
cin.ignore();
cin>>ya;
cin.ignore();
cin>>xb;
cin.ignore();
cin>>yb;
cin.ignore();
cin>>xc;
cin.ignore();
cin>>yc;
cin.ignore();
cin>>xd;
cin.ignore();
cin>>yd;
double pc = (xb-xd)*(yc-yd)-(yb-yd)*(xc-xd);
double qc = (xa-xd)*(yc-yd)-(ya-yd)*(xc-xd);
double m = (xa-xc)*(yb-yd)-(ya-yc)*(xb-xd);
double p=pc/m, q=qc/m;
if(0<=p&&p<=1 && 0<=q&&q<=1) cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}
|
#include <iostream>
#include <complex>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
typedef complex<double> P;
#define X real()
#define Y imag()
double check(P p1, P p2, P p3, P p4)
{
return ((p1.X-p2.X)*(p3.Y-p1.Y) + (p1.Y-p2.Y)*(p1.X-p3.X)) * ((p1.X-p2.X)*(p4.Y-p1.Y) + (p1.Y-p2.Y)*(p1.X-p4.X));
}
int main(void)
{
double x[4],y[4];
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",x,y,x+1,y+1,x+2,y+2,x+3,y+3)) {
P a(x[0], y[0]);
P b(x[1], y[1]);
P c(x[2], y[2]);
P d(x[3], y[3]);
if(check(a,c,b,d) > 0.0 || check(b,d,a,c) > 0.0)
puts("NO");
else
puts("YES");
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <sstream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define bitcount(b) __builtin_popcount(b)
#define all(n) n.begin(),n.end()
typedef pair<double,double> P;
#define x first
#define y second
double tri(P a,P b, P c){
a.x -= c.x, a.y -= c.y;
b.x -= c.x, b.y -= c.y;
c.x -= c.x, c.y -= c.y;
return fabs( b.x * a.y - a.x * b.y ) / 2.0;
}
int main(){
vector<P> d(4);
string line;
while( getline(cin,line) ){
while(~line.find(","))line[line.find(",")] = ' ';
stringstream ss(line);
rep(i,4)ss >> d[i].x >> d[i].y;
double S = tri(d[0],d[2],d[1]) + tri(d[0],d[2],d[3]);
bool flag = true;
rep(i,4){
double s = tri(d[0],d[2],d[1]) + tri(d[0],d[2],d[3]);
if( s != S)flag = false;
rotate(d.begin(),d.begin()+1,d.end());
}
cout << (flag?"YES":"NO") << endl;
}
}
|
#include<iostream>
#include<cstdlib>
#include<complex>
using namespace std;
typedef complex<double> Po;
double cross(Po a,Po b)
{
return a.real()*b.imag() - a.imag()*b.real();
}
double area(Po a,Po b, Po c)
{
return abs(cross(b-a,c-a))/2;
}
bool inter(Po a, Po b,Po c,Po x)
{
return (fabs(area(a,b,x)+area(b,c,x)+area(c,a,x)-area(a,b,c))<1e-10);
}
int main()
{
Po p[4];
double a, b;
char c, d;
while(cin >> a >> c >> b){
p[0] = Po(a, b);
for(int i=1; i<4; i++)
{
cin >> c >> a >> d >> b;
p[i] = Po(a, b);
}
if(inter(p[0],p[1],p[2],p[3]) || inter(p[0],p[2],p[3],p[1]) || inter(p[0],p[1],p[3],p[2]) || inter(p[1],p[2],p[3],p[0]))
cout << "NO\n";
else cout << "YES\n";
}
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif
int main(int argc, char **argv){
double xa, ya, xb, yb, xc, yc, xd, yd;
#if INPUT_FROM_FILE
//std::ifstream ifs("test.txt");
FILE *fp = fopen("test.txt", "r");
#endif
#if INPUT_FROM_FILE
while(fscanf(fp, "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF){
#else
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF){
#endif
double calc0 = (xb - xa) * (yc - yb) - (xc - xb) * (yb - ya);
double calc1 = (xc - xb) * (yd - yc) - (xd - xc) * (yc - yb);
double calc2 = (xd - xc) * (ya - yd) - (xa - xd) * (yd - yc);
double calc3 = (xa - xd) * (yb - ya) - (xb - xa) * (ya - yd);
if((calc0 > 0 && calc1 > 0 && calc2 > 0 && calc3 > 0) ||
(calc0 < 0 && calc1 < 0 && calc2 < 0 && calc3 < 0)){
std::cout << "YES" << std::endl;
}
else{
std::cout << "NO" << std::endl;
}
}
return 0;
}
|
#include <iostream>
#include <complex>
using namespace std;
typedef complex<double> P;
double cross(P a, P b){
return a.real() * b.imag() - a.imag() * b.real();
}
double dot(P a, P b){
return a.real() * b.real() + a.imag() * b.imag();
}
int ccw(P a, P b, P c){
b -= a; c -= a;
if(cross(b, c) > 0) return 1;
if(cross(b, c) < 0) return -1;
if(dot(b, c) < 0) return 2;
if(norm(b) < norm(c)) return -2;
return 0;
}
int main()
{
char j;
double a,b,c,d,e,f,g,h;
for(;cin>>a>>j>>b>>j>>c>>j>>d>>j>>e>>j>>f>>j>>g>>j>>h;)
{
P x(a,b),y(c,d),z(e,f),p(g,h);
if(ccw(x,y,z)==ccw(y,z,p) && ccw(y,z,p) == ccw(z,p,x)
&& ccw(z,p,x) == ccw(p,x,y))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
|
#include <stdio.h>
#include <complex>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef complex<double> P;
double cross(const P& a, const P& b) { return imag(conj(a)*b); }
P ps[4];
bool is() {
const double sig = cross(ps[1]-ps[0], ps[2]-ps[0]);
rep (i, 4) {
const int j = (i+1)%4;
const int k = (i+2)%4;
if (cross(ps[j]-ps[i], ps[k]-ps[i])*sig < 0) return false;
}
return true;
}
int main() {
double x[4], y[4];
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
x, y, x+1, y+1, x+2, y+2, x+3, y+3) != EOF) {
rep (i, 4) ps[i] = P(x[i], y[i]);
puts(is() ? "YES" : "NO");
}
return 0;
}
|
#include <cstdio>
typedef struct
{
double x, y;
} Point;
bool intersect(const Point& p1, const Point& p2, const Point& p3, const Point& p4)
{
if (((p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x)) *
((p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x)) < 0)
return true;
return false;
}
int main()
{
Point a, b, c, d;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
&a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &d.x, &d.y) != EOF) {
if(intersect(a, c, b, d) && intersect(b, d, a, c))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main(){
double x[4];
double y[4];
char c;
while(cin >> x[0] >> c >> y[0]){
for(int i=1;i<4;i++){
cin >> c >> x[i] >> c >> y[i];
}
bool flag1 = 0;
bool flag2 = 0;
for(int i=0;i<4;i++){
if((x[(i+2)%4]-x[i%4])*(y[(i+1)%4]-y[i%4])-(y[(i+2)%4]-y[i%4])*(x[(i+1)%4]-x[i%4])>0){
flag1=1;
}
else{
flag2=1;
}
}
if(flag1 && flag2){
cout << "NO" << endl;
}
else if(flag1 || flag2){
cout << "YES" <<endl;
}
else{
cout << "NO" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
double x[4],y[4];
char c;
while(cin>>x[0]>>c>>y[0]>>c>>x[1]>>c>>y[1]>>c>>x[2]>>c>>y[2]>>c>>x[3]>>c>>y[3]){
double a[4],b[4];
for(int i=0;i<4;i++){
a[i] = x[(i+1)%4]-x[i];
b[i] = y[(i+1)%4]-y[i];
}
double c[4];
for(int i=0;i<4;i++) c[i] = a[i]*b[(i+1)%4] - a[(i+1)%4]*b[i];
int d = 0;
for(int i=0;i<4;i++) if(c[i]>0.0) d++;
if(d==4 or d==0) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
|
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
double x[4];
double y[4];
char ten;
while( cin >> x[0] >> ten >> y[0] ){
cin >> ten >> x[1] >> ten >> y[1] >> ten >> x[2] >> ten >> y[2] >> ten >> x[3] >> ten >> y[3];
double Area = 0;
int I;
for( int i = 0 ; i < 4 ; i++ ){//座標から多角形の面積を求める公式
if( i == 3 ){
I = 0;
}
else{
I = i + 1;
}
Area += ( x[i] * y[I] ) - ( x[I] * y[i] );
}
Area = abs(Area) / 2;
double area[4];
area[0] = x[0]*y[1] - x[1]*y[0] + x[1]*y[2] - x[2]*y[1] + x[2]*y[0] - x[0]*y[2];
area[1] = x[1]*y[2] - x[2]*y[1] + x[2]*y[3] - x[3]*y[2] + x[3]*y[1] - x[1]*y[3];
area[2] = x[2]*y[3] - x[3]*y[2] + x[3]*y[0] - x[0]*y[3] + x[0]*y[2] - x[2]*y[0];
area[3] = x[3]*y[0] - x[0]*y[3] + x[0]*y[1] - x[1]*y[0] + x[1]*y[3] - x[3]*y[1];
for( int i = 0 ; i < 4 ; i++ ){
area[i] = abs(area[i]) / 2;
}
double AREA = area[0] + area[1] + area[2] + area[3];
//cout << area[0] << "---" << area[1] << "---" << area[2] << "---" << area[3]<< endl;
//cout << Area << endl;
//cout << AREA << endl;
if( AREA == 2*Area ) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
|
#include<iostream>
using namespace std;
struct Point{
double x,y;
void init(double a,double b){x=a;y=b;}
bool turn(Point p){return (x*p.y - y*p.x)>=0;}
};
int main()
{
Point A,B,C,D,AB,BC,CD,DA;
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&D.x,&D.y)){
AB.init(B.x-A.x,B.y-A.y);
BC.init(C.x-B.x,C.y-B.y);
CD.init(D.x-C.x,D.y-C.y);
DA.init(A.x-D.x,A.y-D.y);
if( (AB.turn(BC)==BC.turn(CD))&&(BC.turn(CD)==CD.turn(DA))&&(CD.turn(DA)==DA.turn(AB)) )puts("YES");
else puts("NO");
}
}
|
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
class Point{
public:
double y, x;
Point(double y0, double x0){
y = y0;
x = x0;
}
Point(){
y = x = 0.0;
}
double cross(const Point& p) const{
return x * p.y - y * p.x;
}
Point operator-(const Point& p) const{
return Point(y - p.y, x - p.x);
}
};
int main()
{
for(;;){
vector<Point> p(4);
for(int i=0; i<4; ++i){
char c;
if(!(cin >> p[i].x >> c >> p[i].y))
return 0;
if(i < 3)
cin >> c;
}
bool plus = true;
bool minus = true;
for(int i=0; i<4; ++i){
Point p1 = p[(i+2)%4] - p[(i+1)%4];
Point p2 = p[i] - p[(i+1)%4];
if(p1.cross(p2) < 0)
plus = false;
else
minus = false;
}
if(plus || minus)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
|
#include <iostream>
class Point
{
public:
double m_X;
double m_Y;
Point(double x, double y)
: m_X( x )
, m_Y( y )
{}
~Point() {}
double DiffX(const Point& rhs) const
{
return(rhs.m_X - m_X);
}
double DiffY(const Point& rhs) const
{
return(rhs.m_Y - m_Y);
}
};
class Vec
{
double m_X;
double m_Y;
public:
Vec(Point start, Point end)
: m_X(end.m_X - start.m_X)
, m_Y(end.m_Y - start.m_Y)
{
}
~Vec() {}
double CrossProduct(const Vec& rhs)
{
return(m_X*rhs.m_Y - m_Y*rhs.m_X);
}
};
int main()
{
double ax, ay, bx, by, cx, cy, dx, dy;
char s;
while (std::cin >> ax >> s >> ay >> s >> bx >> s >> by >> s >> cx >> s >> cy >> s >> dx >> s >> dy)
{
Point a(ax, ay);
Point b(bx, by);
Point c(cx, cy);
Point d(dx, dy);
Vec ab(a, b);
Vec bc(b, c);
Vec cd(c, d);
Vec da(d, a);
double cp_ab = ab.CrossProduct(bc);
double cp_bc = bc.CrossProduct(cd);
double cp_cd = cd.CrossProduct(da);
double cp_da = da.CrossProduct(ab);
if ( (cp_ab > 0 && cp_bc > 0 && cp_cd > 0 && cp_da > 0) || ((cp_ab < 0 && cp_bc < 0 && cp_cd < 0 && cp_da < 0)) )
{
std::cout << "YES" << std::endl;
}
else
{
std::cout << "NO" << std::endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(void){
double x1,x2,x3,x4,y1,y2,y3,y4, tmp1, tmp2, tmp3, tmp4;
char c;
while (cin>>x1>>c>>y1>>c>>x2>>c>>y2>>c>>x3>>c>>y3>>c>>x4>>c>>y4){
tmp1 = (y2-y1)*(x3-x1)-(y3-y1)*(x2-x1);
tmp2 = (y4-y1)*(x3-x1)-(y3-y1)*(x4-x1);
tmp3 = (y1-y2)*(x4-x2)-(y4-y2)*(x1-x2);
tmp4 = (y3-y2)*(x4-x2)-(y4-y2)*(x3-x2);
if (tmp1*tmp2<0 && tmp3*tmp4<0) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
|
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <cstdlib>
using namespace std;
typedef long long LL;
static const double EPS = 1e-9;
#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int judge(double t1, double t2){
int j=1;
if(abs(t2-t1)>M_PI) j*=-1;
if(t2-t1<0) j*=-1;
return j;
}
int main(void){
double x[4],y[4],t[4];
while(cin>>x[0]){
int s = 0;
cin.ignore();
cin >> y[0];
for(int i=1;i<4;i++){
cin.ignore();
cin >> x[i];
cin.ignore();
cin >> y[i];
}
REP(i,4)
t[i] = atan2(y[(i+1)%4]-y[i], x[(i+1)%4]-x[i]);
REP(i,4)
s+=judge(t[i],t[(i+1)%4]);
if(abs(s) == 4)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
double dot(P a,P b){return real(conj(a)*b);}
double cross(P a,P b){return imag(conj(a)*b);}
int main(){
double a,b,c,d,e,f,g,h;
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a,&b,&c,&d,&e,&f,&g,&h)){
P x[6];
x[0] = P(a,b);
x[1] = P(c,d);
x[2] = P(e,f);
x[3] = P(g,h);
x[4] = x[0];
x[5] = x[1];
double ccw = cross(x[2]-x[0],x[1]-x[0]);
bool flag = true;
REPR(i,4){
double ccc = cross(x[2+i]-x[i],x[1+i]-x[i]);
if(ccw*ccc <= 0){
flag = false;
break;
}
}
if(flag){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
return 0;
}
|
#include <stdio.h>
#define S(x,y,a,b,l,r) ((x*b+a*r+l*y-y*a-l*b-r*x)>0?0:((x*b+a*r+l*y-y*a-l*b-r*x)<0?1:2))
int main() {double a,b,c,d,o,p,q,r;while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a,&b,&c,&d,&o,&p,&q,&r)!=EOF) {int T[4]={0,0,0,0};T[S(a,b,c,d,o,p)]++,T[S(c,d,o,p,q,r)]++,T[S(o,p,q,r,a,b)]++,T[S(q,r,a,b,c,d)]++;if (T[0]&&T[1]) puts("NO"); else puts("YES");} return 0;}
|
#include <stdio.h>
bool is_up(const float x1, const float y1,
const float x2, const float y2,
const float xp, const float yp){
float y = 0.0;
y = (y2 - y1)/(x2 - x1)*(xp - x1) + y1;
return yp > y;
}
int main(void){
float x[4];
float y[4];
while(scanf("%f,%f,%f,%f,%f,%f,%f,%f",
x, y, x+1, y+1, x+2, y+2, x+3, y+3) != EOF){
if(is_up(x[0], y[0], x[2], y[2], x[1], y[1]) ^
is_up(x[0], y[0], x[2], y[2], x[3], y[3]) == 0){
puts("NO");
}else if(is_up(x[1], y[1], x[3], y[3], x[2], y[2]) ^
is_up(x[1], y[1], x[3], y[3], x[0], y[0]) == 0){
puts("NO");
}else{
puts("YES");
}
}
return 0;
}
|
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>
using namespace std;
#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
#define X real()
#define Y imag()
typedef complex<double> P;
double cross(P a,P b){return a.X*b.Y-a.Y*b.X;}
bool ccw(P a,P b,P c){return cross(b-a,c-a)>=0;}
int main(){
double a[8];
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7])!=EOF){
P b[4];
rep(i,4)b[i]=P((double)a[i*2],(double)a[i*2+1]);
bool ok = true;
rep(i,4){
if(!ccw(b[i],b[(i+1)%4],b[(i+2)%4]))ok=false;
}
bool ok2 = true;
rep(i,4){
if(!ccw(b[i],b[(i+3)%4],b[(i+2)%4]))ok2=false;
}
if(ok||ok2)puts("YES");
else puts("NO");
}
}
|
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define EPS (1e-10)
double len(double x1, double y1, double x2, double y2){
return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
double heron(double a, double b, double c){
double z = (a+b+c) / 2.0;
return sqrt(z*(z-a)*(z-b)*(z-c));
}
int main(){
double x0, x1, x2, x3, y0 ,y1 ,y2, y3;
double ab, bc, cd ,da, ca, db, abc, bcd, cda, dab, maxS;
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3)){
ab = len(x0,y0,x1,y1);
bc = len(x1,y1,x2,y2);
cd = len(x2,y2,x3,y3);
da = len(x3,y3,x0,y0);
ca = len(x0,y0,x2,y2);
db = len(x1,y1,x3,y3);
abc = heron(ab, bc, ca);
bcd = heron(bc, cd, db);
cda = heron(cd, da, ca);
dab = heron(da, ab, db);
maxS = max(max(abc, bcd), max(cda, dab));
if(fabs(maxS*2.0 - (abc+bcd+cda+dab)) < EPS){
cout << "NO" << endl;
}else{
cout << "YES" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
double EPS=1e-10;
double add(double a, double b)
{
if(abs(a+b)<EPS*(abs(a)+abs(b))) return 0;
return a+b;
}
double x[5],y[5];
bool input()
{
bool suc=false;
for(int i=0;i<4;i++)
{
if(!i && scanf("%lf,%lf",&x[i],&y[i])!=EOF) suc=true;
else if(i && scanf(",%lf,%lf",&x[i],&y[i])!=EOF) suc=true;
}
if(suc) return true;
else return false;
}
int main()
{
while(input())
{
bool failed=false; x[4]=x[0],y[4]=y[0];
double vx[5],vy[5];
for(int i=0;i<4;i++) vx[i]=x[i+1]-x[i],vy[i]=y[i+1]-y[i];
vx[4]=vx[0],vy[4]=vy[0];
bool plus=true;
if(add(vx[0]*vy[1],-vy[0]*vx[1])<0) plus=false;
for(int i=0;i<4;i++)
{
if(plus && add(vx[i]*vy[i+1],-vy[i]*vx[i+1])<0 ) failed=true;
else if(!plus && add(vx[i]*vy[i+1],-vy[i]*vx[i+1])>0 ) failed=true;
}
if(failed) cout << "NO" << '\n' ;
else cout << "YES" << '\n' ;
}
}
|
#include<iostream>
#include<cmath>
struct vector
{
double x, y;
double norm()
{
return hypot(x, y);
}
vector operator-(vector v)
{
vector result;
result.x = x - v.x;
result.y = y - v.y;
return result;
}
double operator*(vector v)
{
return x * v.x + y * v.y;
}
};
double area(vector v1, vector v2, vector v3)
{
vector side1 = v2 - v1, side2 = v3 - v1;
return sqrt(pow(side1.norm() * side2.norm(), 2) - pow(side1 * side2, 2)) / 2;
}
int main()
{
while (true)
{
vector A, B, C, D;
char foo;
std::cin >> A.x >> foo >> A.y >> foo >> B.x >> foo >> B.y >> foo >> C.x >> foo >> C.y >> foo >> D.x >> foo >> D.y;
if (std::cin.eof())
{
break;
}
double ABC = area(A, B, C),
ACD = area(A, C, D),
BCD = area(B, C, D),
ABD = area(A, B, D);
std::cout << (ABC + ACD > ABD && ABC + ACD > BCD && ABD + BCD > ABC && ABD + BCD > ACD ? "YES" : "NO") << std::endl;
}
return 0;
}
|
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
using namespace std;
using P = pair<double,double>;
constexpr int n = 10;
double cross(const P &p1,const P &p2){
return p1.first*p2.second - p2.first*p1.second;
}
int main(){
string str;
while(getline(cin,str)){
double tmp[8];
P p[4];
string tmpstr;
istringstream stream(str);
for(int i=0;getline(stream,tmpstr,',')&&i<8;++i){
tmp[i] = stof(tmpstr);
}
for(int i=0;i<4;++i){
p[i].first = tmp[(i+1)%4*2]-tmp[i*2];
p[i].second = tmp[(i+1)%4*2+1]-tmp[i*2+1];
// cout << p[i].first << "," << p[i].second << endl;
}
bool allpos = true ,allneg = true;
for(int i=0;i<4;++i){
double val = cross(p[i],p[(i+1)%4]);
// cout << val << endl;
allpos = allpos && val>0;
allneg = allneg && val<0;
}
bool isconvex = allneg||allpos;
if(isconvex){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}
}
|
#include <iostream>
#include <cstdio>
using namespace std;
double cross(double x1, double y1, double x2, double y2, double x3, double y3) {
double xx1 = x2-x1, yy1 = y2-y1;
double xx2 = x3-x1, yy2 = y3-y1;
return (xx1*yy2 - xx2*yy1);
}
int main() {
double xa,xb,xc,xd,ya,yb,yc,yd;
while (scanf(
"%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd) == 8) {
double p = cross(xa, ya, xb, yb, xc, yc);
bool convex = true;
if (p*cross(xb, yb, xc, yc, xd, yd) < 0.0) convex = false;
if (p*cross(xc, yc, xd, yd, xa, ya) < 0.0) convex = false;
if (p*cross(xd, yd, xa, ya, xb, yb) < 0.0) convex = false;
cout << (convex ? "YES" : "NO") << endl;
}
return 0;
}
|
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <cmath>
#include <sstream>
#define F first
#define S second
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
typedef pair<double, double> pdd;
const double EPS = 10e-6;
double wid(pdd a, pdd b) {
return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}
double yoge(pdd a, pdd b, pdd c) {
double A, B, C;
C = wid(a, b); A = wid(b, c); B = wid(c, a);
return abs(acos((B*B+C*C-A*A)/(2*B*C)));
}
int main() {
pdd p[4];
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&p[0].first,&p[0].second,&p[1].first,&p[1].second,&p[2].first,&p[2].second,&p[3].first,&p[3].second)!=EOF) {
double x=yoge(p[0],p[3],p[1])/3.1415926535*180+
yoge(p[1],p[0],p[2])/3.1415926535*180+
yoge(p[2],p[1],p[3])/3.1415926535*180+
yoge(p[3],p[2],p[0])/3.1415926535*180-360;
if(x<EPS&&x>-1*EPS)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)
using namespace std;
//三角形面積(三点から)
double smen(double x1, double y1, double x2, double y2, double x3, double y3){
double wkk;
wkk =((x3-x2) * (y1-y2) - (x1-x2) * (y3-y2) )* 0.5;
if(wkk < 0) wkk *= -1;
return wkk;
}
int main(void){
double xa,xb,xc,xd,ya,yb,yc,yd;
int cnt=0;
char k;
while(!cin.eof() && cnt < 50){
cin >> xa >> k >> ya >> k >> xb >> k >> yb >> k
>> xc >> k >> yc >> k >> xd >> k >> yd ;
if(cin.eof()) break;
double s1 = smen(xa,ya,xb,yb,xc,yc);
double s1b= smen(xa,ya,xc,yc,xd,yd);
double s2 = smen(xa,ya,xb,yb,xd,yd);
double s2b= smen(xb,yb,xc,yc,xd,yd);
if(s1+s1b==s2+s2b) cout << "YES" << endl;
else cout << "NO" << endl;
// cin.clear();
cnt++;
}
return 0;
}
|
#include<iostream>
#include<stdio.h>
using namespace std;
typedef struct point{
double x,y;
} point;
double cross(point p1, point p2, point p3, point p4){
return ( (p1.x-p2.x)*(p3.y-p1.y) + (p1.y-p2.y)*(p1.x-p3.x)) * ((p1.x-p2.x)*(p4.y-p1.y) + (p1.y-p2.y)*(p1.x-p4.x));
}
int main(){
char a;
double l[4];
while(1){
bool ans = true;
point p[4];
for(int i=0;i<4;i++)
if(scanf("%lf,%lf,",&p[i].x,&p[i].y) == EOF) return 0;
if(cross(p[0],p[2],p[1],p[3]) > 0.0 || cross(p[1],p[3],p[0],p[2] ) > 0.0) ans = false;
if(ans == true) {cout << "YES" << endl;} else {cout << "NO" << endl; }
}
}
|
#include <iostream>
#include <stdio.h>
using namespace std;
bool check(double X1,double Y1,double X2,double Y2,double X3,double Y3,double X4,double Y4)
{
return((X1 - X2) * (Y3 - Y1) - (Y1 - Y2) * (X3 - X1)) * ((X1 - X2) *(Y4 - Y1) - (Y1 - Y2) * (X4 - X1)) > 0.0;
}
void solve()
{
double xa, ya, xb, yb, xc, yc, xd, yd;
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) )
if(check(xa,ya,xc,yc,xb,yb,xd,yd) || check(xb,yb,xd,yd,xa,ya,xc,yc))
{
cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
}
}
int main()
{
solve();
return(0);
}
|
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 998244353;
const long long inf = 1ll << 61;
const double eps = 0.000000000001;
typedef pair<int, int> P;
typedef pair<P, int>PP;
struct edge { int to; int cost; };
double det(double x11,double x12,double x21,double x22) {
return x11*x22 - x12*x21;
}
signed main() {
double x[4],y[4];
while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])) {
double ans[4];
rep(i, 4) {
ans[i] = det(x[(i + 1) % 4] - x[i], y[(i + 1) % 4] - y[i], x[(i + 2) % 4] - x[i], y[(i + 2) % 4] - y[i]);
}
rep(i, 3)ans[0] *= ans[i + 1];
if (ans[0] > 0)puts("YES");
else puts("NO");
}
}
|
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
typedef complex <double> P;
#define X real()
#define Y imag()
double func(P p1, P p2, P p3, P p4){
return ( (p1.X-p2.X)*(p3.Y-p1.Y) + (p1.Y-p2.Y)*(p1.X-p3.X)) * ((p1.X-p2.X)*(p4.Y-p1.Y) + (p1.Y-p2.Y)*(p1.X-p4.X));
}
int main(void)
{
double x1, x2, x3, x4, y1, y2, y3, y4;
char a;
while (cin>>x1>>a>>y1>>a>>x2>>a>>y2>>a>>x3>>a>>y3>>a>>x4>>a>>y4){
P a(x1, y1);
P b(x2, y2);
P c(x3, y3);
P d(x4, y4);
if (0.0 < func(a, c, b, d) || 0.0 < func(b, d, a, c)) cout << "NO" << endl;
else cout << "YES" << endl;
}
return 0;
}
|
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
int main() {
double x1, x2, x3, x4, y1, y2, y3, y4, dist1, dist2, dist3, dist4, dist5, dist6;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4) != EOF) {
dist1 = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
dist2 = sqrt((x2 - x4) * (x2 - x4) + (y2 - y4) * (y2 - y4));
dist3 = fabs((y2 - y4) * x1 + (x4 - x2) * y1 + y2 * (x2 - x4) - x2 * (y2 - y4)) / (sqrt((y2 - y4) * (y2 - y4) + (x4 - x2) * (x4 - x2)));
dist4 = fabs((y1 - y3) * x2 + (x3 - x1) * y2 + y1 * (x1 - x3) - x1 * (y1 - y3)) / (sqrt((y1 - y3) * (y1 - y3) + (x3 - x1) * (x3 - x1)));
dist5 = fabs((y2 - y4) * x3 + (x4 - x2) * y3 + y2 * (x2 - x4) - x2 * (y2 - y4)) / (sqrt((y2 - y4) * (y2 - y4) + (x4 - x2) * (x4 - x2)));
dist6 = fabs((y1 - y3) * x4 + (x3 - x1) * y4 + y1 * (x1 - x3) - x1 * (y1 - y3)) / (sqrt((y1 - y3) * (y1 - y3) + (x3 - x1) * (x3 - x1)));
if (dist1 < dist3 || dist2 < dist4 || dist1 < dist5 || dist2 < dist6) {
printf("NO\n");
}
else {
printf("YES\n");
}
}
return 0;
}
|
#include <cstdio>
using namespace std;
struct Point { double x, y; };
bool intersect(Point a, Point b, Point c, Point d) {
return ((a.x - b.x) * (c.y - a.y) + (a.y - b.y) * (a.x - c.x)) * ((a.x - b.x) * (d.y - a.y) + (a.y - b.y) * (a.x - d.x)) < 0;
}
int main() {
Point A, B, C, D;
while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y, &D.x, &D.y)) {
if (intersect(A, C, B, D) && intersect(B, D, A, C)) puts("YES");
else puts("NO");
}
}
|
#include <cstdio>
using namespace std;
struct Point {
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));}
};
double cross(Point a, Point b)
{
return (a.x * b.y - a.y * b.x);
}
int ccw(Point x, Point y)
{
if (cross(x, y) > 0) return (+1);
return (0);
}
int main()
{
Point a, b, c, d;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &d.x, &d.y) != EOF){
int dir = ccw(b - a, c - a) + ccw(c - b, d - b) + ccw(d - c, a - c) + ccw(a - d, b - d);
printf("%s\n", dir % 4 ? "NO" : "YES");
}
return (0);
}
|
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
vector<string> split(const string &str, char delim){
vector<string> res;
size_t current = 0, found;
while((found = str.find_first_of(delim, current)) != string::npos){
res.push_back(string(str, current, found - current));
current = found + 1;
}
res.push_back(string(str, current, str.size() - current));
return res;
}
double isCross(double p1_x,double p1_y,double p2_x,double p2_y,double p3_x,double p3_y,double p4_x,double p4_y){
return ( (p1_x-p2_x)*(p3_y-p1_y) + (p1_y-p2_y)*(p1_x-p3_x)) * ((p1_x-p2_x)*(p4_y-p1_y) + (p1_y-p2_y)*(p1_x-p4_x));
}
int main()
{
string s;
while(cin >> s)
{
vector<string> _s = split(s,',');
double *a = new double[8];
for(int i=0;i<8;i++)
{
a[i] = atoi(_s[i].c_str());
}
if(isCross(a[0],a[1],a[4],a[5],a[2],a[3],a[6],a[7]) > 0.0 || isCross(a[2],a[3],a[6],a[7],a[0],a[1],a[4],a[5]) > 0.0)
{
cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
}
}
return 0;
}
|
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main(void){
double xa,ya,xb,yb,xc,yc,xd,yd;
double sikaku;
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF){
sikaku=abs(((xa*yb+xb*yc+xc*yd+xd*ya)-(xb*ya+xc*yb+xd*yc+xa*yd))/2);
xb-=xa,xc-=xa,xd-=xa,xa=0;
yb-=ya,yc-=ya,yd-=ya,ya=0;
if(sikaku==(abs((xb*yc-yb*xc)/2)+abs((xc*yd-yc*xd)/2))){
xa-=xd,xb-=xd,xc-=xd,xd=0;
ya-=yd,yb-=yd,yc-=yd,yd=0;
if(sikaku==(abs((xb*ya-yb*xa)/2)+abs((xc*yb-yc*xb)/2))) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else cout<<"NO"<<endl;
}
return 0;
}
|
#include <stdio.h>
int main(void) {
double x[4], y[4];
int i, j;
while(scanf("%lf,%lf", &x[0], &y[0]) != EOF) {
for(i = 1; i < 4; ++i) scanf(",%lf,%lf", &x[i], &y[i]);
int s, ans = 1;
if((x[1] - x[0]) * (y[2] - y[0]) - (y[1] - y[0]) * (x[2] - x[0]) > 0) s = 1;
else s = 0;
for(i = 1; i < 4; ++i) {
double tmp = (x[(i + 1) % 4] - x[i]) * (y[(i + 2) % 4] - y[i]) - (y[(i + 1) % 4] - y[i]) * (x[(i + 2) % 4] - x[i]);
if((s && tmp < 0) || (!s && tmp > 0)) {
ans = 0;
break;
}
}
if(ans) printf("YES\n");
else printf("NO\n");
}
return 0;
}
|
#include <cstdio>
using namespace std;
int main(){
float p[4][2];
while(scanf("%f,%f,%f,%f,%f,%f,%f,%f"
,&p[0][0],&p[0][1],&p[1][0],&p[1][1],&p[2][0],&p[2][1],&p[3][0],&p[3][1])>0){
for(int i=0;i<4;i++){
int n,m;
float a1,a2,b1,b2,xp,yp,A,B;
a1=p[(i+1)%4][0]-p[i%4][0];
a2=p[(i+1)%4][1]-p[i%4][1];
b1=p[(i+3)%4][0]-p[i%4][0];
b2=p[(i+3)%4][1]-p[i%4][1];
xp=p[(i+2)%4][0]-p[i%4][0];
yp=p[(i+2)%4][1]-p[i%4][1];
A=(b1*yp-b2*xp)/(a2*b1-a1*b2);
B=(a2*xp-a1*yp)/(a2*b1-a1*b2);
if(A+B<1&&A>0&&B>0){
printf("NO\n");
break;
}
if(i==3) printf("YES\n");
}
}
return 0;
}
|
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
//??´???AB????§?????????´???BC????§??????????RotType????¨????(A???B???C????????§??????)
//RotType = ????????¢1, ????????¢-1, ??´???0
int getRotType( double angle_a, double angle_b ){
const int eps = 1e-8;
const double PAI = 3.14159265358979;
if( fabs(angle_a - angle_b) <= eps )
return 0;
if( angle_a > angle_b + PAI )
angle_b += 2 * PAI;
else if( angle_b > angle_a + PAI )
angle_a += 2 * PAI;
if( angle_b > angle_a ) //?§????????¢????????????????
return 1;
return -1; //?§???????????°?????????????
}
int main()
{
double x[4], y[4];
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]) != -1)
{
//A???B???C, B???C???D, C???D???A?????????????????¨???????????????????????????
double ang[4];
for( int i = 0; i < 4; i++ )
ang[i] = atan2(y[(i+1)%4] - y[i%4], x[(i+1)%4] - x[i%4]);
double angType[4];
for( int i = 0; i < 4; i++ )
angType[i] = getRotType( ang[i], ang[(i+1)%4] );
int i;
for( i = 0; i < 3; i++ ){
if( angType[i] != angType[i+1] )
break;
}
if( i == 3 )
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <iostream>
#include <cmath>
using namespace std;
double theta(int x, int y) {
double h = sqrt(pow(x,2)+pow(y,2));
double t = asin(y / h);
if (x >= 0 && y >= 0)
return t;
else if (x < 0 && y >= 0)
return M_PI - t;
else if (x < 0 && y < 0)
return M_PI - t;
else
return 2 * M_PI + t;
}
int hoge(double p1[2], double p2[2], double p3[2])
{
double theta1 = theta(p2[0] - p1[0], p2[1] - p1[1]);
double theta2 = theta(p3[0] - p1[0], p3[1] - p1[1]);
if (0 <= theta1 && theta1 <= M_PI)
if (theta1<=theta2 && theta2 <= theta1 + M_PI)
return 1;
else
return -1;
else
if (theta1 <= theta2 || theta2 <= (theta1 - M_PI))
return 1;
else
return -1;
}
int main(void) {
double p[4][2];
char c;
while (cin >> p[0][0]>> c >> p[0][1]) {
for (int i = 1; i < 4; ++i)
cin >> c >> p[i][0] >> c >> p[i][1];
int sum = 0;
for (int i = 0; i < 4; ++i)
sum += hoge(p[i], p[(i+1)%4], p[(i+2)%4]);
cout << ((sum==4 || sum==-4)? "YES" : "NO") << endl;
}
return 0;
}
|
//0035 s it Convex
//http://www5d.biglobe.ne.jp/~tomoya03/shtml/algorithm/Intersection.htm ±±©çl¦qØ
#include<iostream>
using namespace std;
struct Point
{
double x, y;
Point(double x,double y):x(x), y(y){}
Point(){}
};
inline double AngleFromLine(const Point &p1, const Point &p2, const Point &to)
{
//(x1-x2)*(y-y1)+(y1-y2)*(x1-x)=0@ª¼üÌ®
return ((p1.x-p2.x)*(to.y-p1.y)+(p1.y-p2.y)*(p1.x-to.x));
}
int main(void)
{
const int N = 4;
while(1)
{
Point p[N];
char dummy;
int i;
for(i = 0; i < N; i++)
{
if(i)
cin >> dummy;
cin >> p[i].x >> dummy >> p[i].y;
}
if(!cin)
break;
double last = 0; //OñÌü«»èÌÊ@0ͼüó¾©ç¡ñÌâèÅͶݵȢ
double current;
bool isConvex = true; //ÊH
for(i = 0; i < N; i++)
{
current = AngleFromLine(p[i], p[(i+1)%N], p[(i+2)%N]);
//OñÆü«ªá¦ÎAÏÍ}CiXÉÈé
if(last * current < 0)
{
isConvex = false;
break;
}
last = current;
}
cout << (isConvex ? "YES": "NO") << endl;
}
return 0;
}
|
#include <cstdio>
#include <cmath>
using namespace std;
int main(void){
double x[4], y[4];
double p[4];
while (scanf("%lf,%lf,", &x[0], &y[0])>0){
scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]);
for (int i=0; i<4; i++){
int j=(i+1)%4;
int k=(i+2)%4;
p[i] = (x[j]-x[i])*(y[k]-y[j])-(x[k]-x[j])*(y[j]-y[i]);
//printf("%lf\n", p[i]);
}
puts(p[0]*p[1]<0||p[1]*p[2]<0||p[2]*p[3]<0||p[3]*p[0]<0 ? "NO": "YES");
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
double d[10];
string s;
void f() {
s += ',';
bool b00l = 0;
int cnt = 0;
double p = 0, sig = 1, pk = 1;
for (char ch : s) {
if (ch == ',') {
d[cnt] = p * sig;
p = 0; sig = 1; cnt++;
b00l = 0; pk = 1;
}
else if (ch == '-')sig = -1;
else if (ch == '.') b00l = 1;
else if (b00l) {
pk /= 10;
p += pk * (ch - '0');
}
else p = p * 10 + ch - '0';
}
}
signed main() {
while (cin >> s) {
f();
if (((d[0] - d[4]) * (d[3] - d[1]) - (d[1] - d[5]) * (d[2] - d[0])) * ((d[0] - d[4]) * (d[7] - d[1]) - (d[1] - d[5]) * (d[6] - d[0])) > 0)cout << "NO\n"; else
if (((d[2] - d[6]) * (d[1] - d[3]) - (d[3] - d[7]) * (d[0] - d[2])) * ((d[2] - d[6]) * (d[5] - d[3]) - (d[3] - d[7]) * (d[4] - d[2])) > 0)cout << "NO\n";
else cout << "YES\n";//0145<=>2367
}
}
|
#include <iostream>
#include <cstdio>
#include <complex>
using namespace std;
const double EPS = 1.0e-6;
int main()
{
double xa,ya,xb,yb,xc,yc,xd,yd;
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd) > 0){
//printf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",xa,ya,xb,yb,xc,yc,xd,yd);
complex<double> v[4];
v[0] = complex<double>(xb-xa, yb-ya);
v[1] = complex<double>(xc-xb, yc-yb);
v[2] = complex<double>(xd-xc, yd-yc);
v[3] = complex<double>(xa-xd, ya-yd);
int p = 0;
int m = 0;
for(int i=0; i<4; i++){
if( imag(conj(v[i])*v[(i+1)%4]) < 0){
m++;
} else {
p++;
}
}
if(m==4||p==4) cout<<"YES";
else cout<<"NO";
cout<<endl;
}
return 0;
}
|
#include<iostream>
#include<cmath>
using namespace std;
int main(){
char c;
double xa,ya,xb,yb,xc,yc,xd,yd,ab,bc,cd,da,aa,bb,cc,dd;
while(cin>>xa){
cin>>c>>ya>>c>>xb>>c>>yb>>c>>xc>>c>>yc>>c>>xd>>c>>yd;
ab=(xb-xa)*(yc-ya)-(yb-ya)*(xc-xa);
bc=(xc-xb)*(yd-yb)-(yc-yb)*(xd-xb);
cd=(xd-xc)*(ya-yc)-(yd-yc)*(xa-xc);
da=(xa-xd)*(yb-yd)-(ya-yd)*(xb-xd);
if(ab*bc<0||bc*cd<0||cd*da<0||da*ab<0)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <stack>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef struct P {
double x;
double y;
} P;
double isCross(P a, P b, P c, P d)
{
return ((a.x - b.x)*(c.y - a.y) + (a.y - b.y)*(a.x - c.x)) * ((a.x - b.x)*(d.y - a.y) + (a.y - b.y)*(a.x - d.x));
}
int main(void)
{
double xa,xb,xc,xd,ya,yb,yc,yd;
while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd)) {
P a = {xa, ya};
P b = {xb, yb};
P c = {xc, yc};
P d = {xd, yd};
if (isCross(a, b, c, d) > 0.0 && isCross(c, d, a, b) > 0.0) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;
struct p{
double x;
double y;
p operator -(p& rh){
p pnt;
pnt.x = this->x - rh.x;
pnt.y = this->y - rh.y;
return pnt;
}
void print(){
cout << this->x << ", " << this->y << endl;
}
};
double cross(p a, p b){
return a.x*b.y - a.y*b.x;
}
bool isLeft(p a, p b, p c){ // c が ab より左ならtrue
//a.print();
//b.print();
//c.print();
//cout << "cross:" << cross(b-a, c-a) << endl << endl;
return (cross(b-a, c-a) > 0);
}
bool isInside(p a, p b, p c, p d){ // d が abc 内部なら true
bool left = false;
bool right = false;
bool m, n, l;
m = isLeft(a, b, d);
n = isLeft(b, c, d);
l = isLeft(c, a, d);
left = m || n || l;
right = !m || !n || !l;
return left^right;
}
int main(){
p pnt[4];
while(scanf("%lf", &pnt[0].x) != EOF){
scanf(",%lf", &pnt[0].y);
for(int i = 1; i < 4; i++){
scanf(",%lf", &pnt[i].x);
scanf(",%lf", &pnt[i].y);
}
bool b = true;
for(int i = 0; i < 4 && b; i++){
b &= !isInside(pnt[(i+0)%4], pnt[(i+1)%4], pnt[(i+2)%4], pnt[(i+3)%4]);
}
if(b){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
double cross_product(double x1,double y1,double x2,double y2){
return x1*y2-x2*y1;
}
int main(){
double x[4],y[4];
while(~scanf("%lf,%lf",&x[0],&y[0])){
rep(i,1,4) scanf(",%lf,%lf",&x[i],&y[i]);
double c=1;
rep(i,0,4){
c*=cross_product(x[(i+1)%4]-x[i],y[(i+1)%4]-y[i],x[(i+2)%4]-x[(i+1)%4],y[(i+2)%4]-y[(i+1)%4]);
//o(c[i]);
}
if(c>0) o("YES");
else o("NO");
}
}
|
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <cmath>
using namespace std;
double triangle(double x1,double y1,double x2,double y2,double x3,double y3) {
double a[2],b[2],theta,al,bl;
a[0] = x2 - x1;
a[1] = y2 - y1;
b[0] = x3 - x1;
b[1] = y3 - y1;
al = sqrt(a[0] * a[0] + a[1] * a[1]);
bl = sqrt(b[0] * b[0] + b[1] * b[1]);
theta = acos((a[0] * b[0] + a[1] * b[1]) / (al * bl));
return al * bl * abs(sin(theta)) / 2;
}
int main() {
double x0,y0,x1,y1,x2,y2,x3,y3;
double abc,bcd,cda,dab,abd,cbd,acd;
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x0,&y0,&x1,&y1,&x2,&y2,&x3,&y3) == 8) {
abc = triangle(x0,y0,x1,y1,x2,y2);
bcd = triangle(x1,y1,x2,y2,x3,y3);
cda = triangle(x2,y2,x3,y3,x0,y0);
dab = triangle(x3,y3,x0,y0,x1,y1);
abd = triangle(x0,y0,x1,y1,x3,y3);
cbd = triangle(x2,y2,x1,y1,x3,y3);
acd = triangle(x0,y0,x2,y2,x3,y3);
if(abc > abd + cbd)
cout << "NO" << endl;
else if(bcd > abc + acd)
cout << "NO" << endl;
else if(cda > abd + bcd)
cout << "NO" << endl;
else if(dab > abc + acd)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
|
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
double ang(double x1, double y1, double x2, double y2) {
return acos((x1 * x2 + y1 * y2) / (sqrt(x1 * x1 + y1 * y1) * sqrt(x2 * x2 + y2 * y2)));
}
int main (void) {
while (true) {
double x1, x2, x3, x4, y1, y2, y3, y4;
if (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4) == EOF) break;
double a = 0;
a += ang(x2 - x1, y2 - y1, x2 - x3, y2 - y3);
a += ang(x3 - x2, y3 - y2, x3 - x4, y3 - y4);
a += ang(x4 - x3, y4 - y3, x4 - x1, y4 - y1);
a += ang(x1 - x4, y1 - y4, x1 - x2, y1 - y2);
if (abs(M_PI * 2 - a) < 0.01) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
struct Vec2d{
double x,y;
};
double cross(Vec2d &A, Vec2d &B){
return A.x*B.y - A.y*B.x;
}
int main(void){
double x[4],y[4];
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])!=EOF){
bool f=true;
for(int i=0;i<4;++i){
double xx[3],yy[3];
double xp = x[i], yp = y[i];
int cnt=0;
for(int j=0;j<4;++j){
if(i==j) continue;
xx[cnt] = x[j];
yy[cnt] = y[j];
++cnt;
}
Vec2d AB,AP,BC,BP,CA,CP;
AB.x = xx[1]-xx[0]; AB.y = yy[1]-yy[0];
BC.x = xx[2]-xx[1]; BC.y = yy[2]-yy[1];
CA.x = xx[0]-xx[2]; CA.y = yy[0]-yy[2];
AP.x = xp-xx[0]; AP.y = yp-yy[0];
BP.x = xp-xx[1]; BP.y = yp-yy[1];
CP.x = xp-xx[2]; CP.y = yp-yy[2];
if(cross(AB,AP)>0.0 && cross(BC,BP)>0.0 && cross(CA,CP)>0.0)
f=false;
else if(cross(AB,AP)<0.0 && cross(BC,BP)<0.0 && cross(CA,CP)<0.0)
f=false;
else ;
}
cout<<((f)?"YES":"NO")<<endl;
}
return 0;
}
|
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>
#include <set>
#include <numeric>
using namespace std;
typedef complex<double> P;
double sq(double x){return x*x;}
double cross(P x,P y){
return x.real() * y.imag() - x.imag() * y.real();
}
int main(){
double x[4],y[4];
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",x,y,x+1,y+1,x+2,y+2,x+3,y+3)){
P p[4];
for (int i = 0; i < 4; i++)
p[i] = P(x[i],y[i]);
bool f[4];
memset(f,0,4);
for (int i = 0; i < 4; i++)
if(cross(p[(i+2)&3] - p[(i+1)&3],p[i] - p[(i+1)&3]) < 0)
f[i] = true;
int sum = accumulate(f,f+4,0);
if(sum == 0 || sum == 4) puts("YES");
else puts("NO");
}
return 0;
}
|
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
struct P{
P(double a, double b){
x = a;y = b;
}
double x, y;
double det(P a){
return x * a.y - y * a.x;
}
P operator-(P a){
return P(x - a.x, y - a.y);
}
};
int main(){
double xa, ya ,xb, yb, xc, yc, xd, yd;
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd)){
P a = P(xa, ya);
P b = P(xb, yb);
P c = P(xc, yc);
P d = P(xd, yd);
P ab = b - a;
P bc = c - b;
P cd = d - c;
P da = a - d;
if((ab.det(bc) <= 0) == (bc.det(cd) <= 0) && (bc.det(cd) <= 0) == (cd.det(da) <= 0) && (cd.det(da) <= 0) == (da.det(ab) <= 0)){
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
}
}
|
#include <cstdio>
#include <iostream>
#include <complex>
using namespace std;
#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)
inline D inprd(const P &a, const P &b){ return (conj(a) * b).X; }
inline D outprd(const P &a, const P &b){ return (conj(a) * b).Y; }
inline D sign(D d){ return (d<0)?-1:d>0?1:0; }
int main(){
string s;
while(getline(cin, s)){
double xa,ya,xb,yb,xc,yc,xd,yd;
sscanf(s.c_str(), "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd);
P a(xa,ya), b(xb,yb), c(xc,yc), d(xd,yd);
double sa = sign(outprd(b-a, d-a));
double sb = sign(outprd(c-b, a-b));
double sc = sign(outprd(d-c, b-c));
double sd = sign(outprd(a-d, c-d));
if(sa == sb && sb == sc && sc == sd){
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
typedef long long ll;
using namespace std;
struct Point{
double x;
double y;
};
bool is_inter(struct Point p1,struct Point p2,
struct Point p3, struct Point p4)
{
if(((p1.x-p2.x) * (p3.y - p1.y) + (p1.y - p2.y) * (p1.x - p3.x))
* ((p1.x - p2.x) * (p4.y - p1.y) + (p1.y - p2.y) * (p1.x - p4.x)) < 0){
return true;
}
return false;
}
int main()
{
double xa, ya, xb, yb, xc, yc, xd, yd;
Point a,b,c,d;
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
&xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd)){
a.x = xa;
a.y = ya;
b.x = xb;
b.y = yb;
c.x = xc;
c.y = yc;
d.x = xd;
d.y = yd;
printf("%s\n",is_inter(a,c,b,d) && is_inter(b,d,a,c) ? "YES" : "NO");
}
}
|
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
using namespace std;
int main () {
double x1,x2,x3,x4,y1,y2,y3,y4;
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x3,&y3,&x2,&y2,&x4,&y4)!=EOF){
double tc=(x1-x2)*(y3-y1)+(y1-y2)*(x1-x3);
double td=(x1-x2)*(y4-y1)+(y1-y2)*(x1-x4);
double ta=(x3-x4)*(y1-y3)+(y3-y4)*(x3-x1);
double tb=(x3-x4)*(y2-y3)+(y3-y4)*(x3-x2);
if(tc*td<0&&ta*tb<0){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
int main() {
typedef struct zahyou {
double x, y;
} z;
z a, b, c, d;
char ch;
while (cin >> a.x) {
cin >> ch >> a.y >> ch >> b.x >> ch >> b.y >> ch >> c.x >> ch >> c.y
>> ch >> d.x >> ch >> d.y;
//cout << a.x << ' ' << a.y << endl;
//cout << b.x << ' ' << b.y << endl;
//cout << c.x << ' ' << c.y << endl;
//cout << d.x << ' ' << d.y << endl;
int f = 0;
double n, m;
n = (a.x - c.x) * (b.y - a.y) - (a.y - c.y) * (b.x - a.x);
m = (a.x - c.x) * (d.y - a.y) - (a.y - c.y) * (d.x - a.x);
//cout << fixed << setprecision(4) << n << ' ' << m << endl;
if (n * m > 0) f = 1;
n = (b.x - d.x) * (a.y - b.y) - (b.y - d.y) * (a.x - b.x);
m = (b.x - d.x) * (c.y - b.y) - (b.y - d.y) * (c.x - b.x);
//cout << fixed << setprecision(4) << n << ' ' << m << endl;
if (n * m > 0) f = 1;
if (!f) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
}
|
#include<iostream>
#include<cstdio>
#define dff 1e-19
using namespace std;
struct vec{
double x;
double y;
};
bool cross(vec a, vec b, vec x, vec y);
int main(){
for(;;){
vec a,b,c,d;
if(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&(a.x),&(a.y),&(b.x),&(b.y),&(c.x),&(c.y),&(d.x),&(d.y)) == EOF) break;
if(cross(a,c,b,d) && cross(b,d,a,c)) cout <<"YES"<<endl;
else cout <<"NO"<<endl;
}
return 0;
}
bool cross(vec a, vec b, vec x, vec y){
vec p,q,r;
p.x = b.x-a.x;
p.y = b.y-a.y;
q.x = x.x-a.x;
q.y = x.y-a.y;
r.x = y.x-a.x;
r.y = y.y-a.y;
if((p.x*q.y-p.y*q.x)*(p.x*r.y-p.y*r.x)<dff) return true;
return false;
}
|
#include <iostream>
#include <algorithm>
#include <complex>
#include <cstdio>
#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()))
using namespace std;
typedef complex<double> P;
double cross (P a, P b) {
return (a.real() * b.imag() - a.imag() * b.real());
}
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 );
}
int main ()
{
double ax, ay, bx, by, cx, cy, dx, dy;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &ax, &ay, &bx, &by, &cx, &cy, &dx, &dy) != EOF) {
P a = P(ax, ay);
P b = P(bx, by);
P c = P(cx, cy);
P d = P(dx, dy);
if (EQ(is_intersected_ls(a, c, d, b), 0.0)) cout << "NO" << endl;
else cout << "YES" << endl;
}
return 0;
}
|
#include<iostream>
#include<cstdio>
using namespace std;
bool C(double a,double b,double c,double d){return a*d-b*c>=0;}
int main()
{
double a,b,c,d,e,f,g,h;
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a,&b,&c,&d,&e,&f,&g,&h))
{
int cnt=C(e-c,f-d,a-c,b-d)+C(g-e,h-f,c-e,d-f)+C(a-g,b-h,e-g,f-h)+C(c-a,d-b,g-a,h-b);
cout<<(cnt==0||cnt==4?"YES":"NO")<<endl;
}
}
|
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
double ab,ac,ad,bc,bd,cd;
bool heron();
int main(){
double xa,ya,xb,yb,xc,yc,xd,yd;
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd) != EOF){
ab = sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb));
ac = sqrt((xa-xc)*(xa-xc) + (ya-yc)*(ya-yc));
ad = sqrt((xa-xd)*(xa-xd) + (ya-yd)*(ya-yd));
bc = sqrt((xb-xc)*(xb-xc) + (yb-yc)*(yb-yc));
bd = sqrt((xb-xd)*(xb-xd) + (yb-yd)*(yb-yd));
cd = sqrt((xc-xd)*(xc-xd) + (yc-yd)*(yc-yd));
bool f = heron();
(f) ? puts("YES") : puts("NO");
}
return 0;
}
bool heron(){
double sq1=0.0,sq2=0.0;
double S,s;
/*sq1*/
s = (ab+ac+bc)*0.5;
S = sqrt(s * (s-ab) * (s-ac) * (s-bc));
sq1 += S;
s = (ac+ad+cd)*0.5;
S = sqrt(s * (s-ac) * (s-ad) * (s-cd));
sq1 += S;
/*sq2*/
s = (ab+ad+bd)*0.5;
S = sqrt(s * (s-ab) * (s-ad) * (s-bd));
sq2 += S;
s = (bc+bd+cd)*0.5;
S = sqrt(s * (s-bc) * (s-bd) * (s-cd));
sq2 += S;
bool j;
(fabs(sq1-sq2) <= 0.01) ? j = true : j = false;
return j;
}
|
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<numeric>
#include<complex>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define reps(i,s,n) for(int i=s;i<n;i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<double> P;
int main(){
IOS;
// ld a[2],b[2],c[2],d[2]
ld x,y;
char c;
P p[4];
while(1){
int che=0;
rep(i,4){
// cin>>x>>c>>y;
if(!((cin>>x).ignore()>>y).ignore()) return 0;
p[i]=P(x,y);
}
bool a[2]={};
rep(i,4){
// cout<<i<< " "<<p[i]<<endl;
P c=p[i]-p[(i+1)%4], d=p[(i+1)%4]-p[(i+2)%4];
// cout<< c<<" "<<d<<endl;
// cout<<i<<c<<d<<endl;
if(c.real()*d.imag()-c.imag()*d.real()>0){
che+=1;
// cout<<i<<c<<d<<endl;
}
// cout<<a[0]<<" "<<a[1]<<endl;
}
cout << ((che<4&&che>0)?"NO":"YES")<<endl;
}
return 0;
}
|
#include <iostream>
#include <cstdio>
using namespace std;
class Point {
public:
double x, y;
};
bool isIntersect(Point p1, Point p2, Point p3, Point p4) {
return ((p1.x - p2.x) * (p3.y - p1.y) + (p1.y - p2.y) * (p1.x - p3.x))
* ((p1.x - p2.x) * (p4.y - p1.y) + (p1.y - p2.y) * (p1.x - p4.x)) < 0;
}
int main () {
Point p[4];
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
&p[0].x, &p[0].y, &p[1].x, &p[1].y, &p[2].x, &p[2].y, &p[3].x, &p[3].y) != EOF) {
if (isIntersect(p[0], p[2], p[1], p[3]) && isIntersect(p[1], p[3], p[0], p[2])) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
|
#include <bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a),end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;
double dist(double x1, double y1, double x2, double y2){
return sqrt( ((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)) );
}
double outputSin(double x, double y, double z){
return acos( (x * x + y * y - z * z) / (2 * x * y) ) ;
}
double inputXY(double x1, double y1, double x2, double y2, double x3, double y3){
double x, y ,z;
x = dist(x1, y1, x2, y2);
y = dist(x2, y2, x3, y3);
z = dist(x3, y3, x1, y1);
return outputSin(x, y, z);
}
int main(){
double x1, y1, x2, y2, x3, y3, x4, y4;
char gar;
while(cin >> x1 >> gar >> y1 >> gar >> x2 >> gar >> y2 >> gar >> x3 >> gar >> y3 >> gar >> x4 >> gar >> y4){
double a, b, c, d;
a = inputXY(x1, y1, x2, y2, x3, y3);
b = inputXY(x2, y2, x3, y3, x4, y4);
c = inputXY(x3, y3, x4, y4, x1, y1);
d = inputXY(x4, y4, x1, y1, x2, y2);
if(abs(a + b + c + d - 2 * M_PI) < 0.00001) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
|
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#include <sstream>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;
bool cross(double x[], double y[]){
REP(i, 4){
double v1, v2, v3;
v1 = (x[(i)%4]-x[(i+1)%4])*(y[(i)%4]-y[(i+3)%4]) - (y[(i)%4]-y[(i+1)%4])*(x[(i)%4]-x[(i+3)%4]);
v2 = (x[(i+1)%4]-x[(i+2)%4])*(y[(i+1)%4]-y[(i+4)%4]) - (y[(i+1)%4]-y[(i+2)%4])*(x[(i+1)%4]-x[(i+4)%4]);
v3 = (x[(i+2)%4]-x[(i+3)%4])*(y[(i+2)%4]-y[(i+5)%4]) - (y[(i+2)%4]-y[(i+3)%4])*(x[(i+2)%4]-x[(i+5)%4]);
if ( !(v1 < 0 && v2 < 0 && v3 < 0) && !(v1 > 0 && v2 > 0 && v3 > 0) ) {
return false;
}
}
return true;
}
int main(){
double x[4], y[4];
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf"
,&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3]) != EOF) {
if (cross(x, y)) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
|
#include<iostream>
#include<cmath>
using namespace std;
typedef double dbl;
dbl x[4], y[4];
bool point(dbl x[], dbl y[], int n) {
dbl nx[3], ny[3];
for (int i = 0, j = 0; i < 4; i++) {
if (i != n) {
nx[j] = x[i];
ny[j++] = y[i];
}
}
dbl S, s[3];
S = fabs((nx[1] - nx[0])*(ny[2] - ny[0]) - (ny[1] - ny[0])*(nx[2] - nx[0])) / 2.0;
for (int i = 0; i < 3; i++) {
nx[i] -= x[n];
ny[i] -= y[n];
}
for (int i = 0; i < 3; i++) {
s[i] = fabs(nx[i] * ny[(i + 1) % 3] - ny[i] * nx[(i + 1) % 3]) / 2.0;
}
if (fabs(S - s[0] - s[1] - s[2]) < 1e-10) return true;
else return false;
}
int main() {
char c;
while (cin >> x[0] >> c >> y[0]) {
int ok = 1;
for (int i = 1; i < 4; i++) {
cin >> c >> x[i] >> c >> y[i];
}
for (int i = 0; i < 4; i++) {
if (point(x, y, i)) {
cout << "NO\n";
ok = 0;
break;
}
}
if(ok) cout << "YES\n";
}
}
|
#include <iostream>
#include <complex>
using namespace std;
constexpr double EPS = 1e-10;
using Point = complex<double>;
double cross(Point p, Point q) { return (conj(p) * q).imag(); }
int main() {
cin.tie(0); ios_base::sync_with_stdio(false);
double a,b,c,d,e,f,g,h;
char z;
while(cin>>a>>z>>b>>z>>c>>z>>d>>z>>e>>z>>f>>z>>g>>z>>h) {
Point p1(a,b),p2(c,d),p3(e,f),p4(g,h);
if(cross(p3-p1,p2-p1)*cross(p4-p2,p3-p2) > 0 && cross(p1-p3,p4-p3) * cross(p2-p4, p1-p4) > 0){
cout << "YES" << '\n';
} else {
cout << "NO" << '\n';
}
}
return 0;
}
|
#include <iostream>
using namespace std;
class Vector2{
public:
Vector2() : x( 0 ), y( 0 ){}
Vector2( Vector2& a ){
x = a.x;
y = a.y;
}
Vector2( Vector2& a, Vector2& b ){
x = b.x - a.x;
y = b.y - a.y;
}
double cross( Vector2& a ){
return ( x * a.y ) - ( y * a.x );
}
double x, y;
};
int main(){
Vector2 a, b, c, d;
char s;
while ( cin >> a.x >> s >> a.y >> s >> b.x >> s >> b.y >> s
>> c.x >> s >> c.y >> s >> d.x >> s >> d.y ){
Vector2 ab( a, b ), bc( b, c ), cd( c, d ), da( d, a );
double ap, bp, cp, dp;
ap = da.cross( ab );
bp = ab.cross( bc );
cp = bc.cross( cd );
dp = cd.cross( da );
if ( ( ap > 0 && bp > 0 && cp > 0 && dp > 0 ) || ( ap < 0 && bp < 0 && cp < 0 && dp < 0 ) ){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}
return 0;
}
|
#include <cstdio>
using namespace std;
int main()
{
double xs[4],ys[4],a,t;
int p,np,ans;
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xs[0],&ys[0],&xs[1],&ys[1],&xs[2],&ys[2],&xs[3],&ys[3])!=EOF){
ans=a=t=0;
for(int i=0;i<4;i++){
p=(i+3)%4;
np=(i+1)%4;
t=(xs[i]-xs[p])*(ys[np]-ys[i])-(ys[i]-ys[p])*(xs[np]-xs[i]);
if(a*t<0){
ans=1;
break;
}
else{
a=t;
}
}
if(ans==0){
printf("YES\n");
}
else{
printf("NO\n");
}
}
return 0;
}
|
#include <iostream>
#define N 4
using namespace std;
int main(){
double x[N], y[N];
char c;
while(cin >> x[0] >> c >> y[0]){
for(int i = 1; i < N; i++){
cin >> c >> x[i] >> c >> y[i];
}
double r[N][2], z[4];
for(int i = 0; i < N; i++){
r[i][0] = x[(i+1)%N] - x[i];
r[i][1] = y[(i+1)%N] - y[i];
}
for(int i = 0; i < N; i++){
z[i] = r[i][0]*r[(i+1)%N][1]-r[(i+1)%N][0]*r[i][1];
}
if(z[0]*z[1]*z[2]*z[3] > 0) cout << "YES" << endl; //??°???????¬????????????????????????°NO
else cout << "NO" << endl;
}
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <complex>
#define EPS 1e-10
#define EQ(a, b) (abs((a) - (b)) < EPS)
using namespace std;
typedef complex<double> P;
double cross(P a, P b) {
return(a.real() * b.imag() - a.imag() * b.real());
}
int is_intersect(P a1, P a2, P b1, P b2) {
return(cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS) &&
(cross(b2-a1, a1-b1) * cross(b2-b1, a2-b1) < EPS);
}
int main(void) {
double xa, ya, xb, yb, xc, yc, xd, yd;
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd) != EOF) {
P a(xa, ya), b(xb, yb), c(xc, yc), d(xd, yd);
if(is_intersect(a, c, b, d) && is_intersect(b, d, a, c)) cout << "YES" << endl;
else cout << "NO" << endl;
}
return(0);
}
|
#include<cstdio>
#include<cmath>
int main(){
double x[4],y[4];
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])!=-1){
bool is=true;
double radsum=0;
for(int i=0;i<4;i++){
int a=i,b=(i+1)%4,c=(i+2)%4;
radsum+=acos((pow(x[a]-x[b],2)+pow(y[a]-y[b],2)+pow(x[b]-x[c],2)+pow(y[b]-y[c],2)-pow(x[c]-x[a],2)-pow(y[c]-y[a],2))/(2*sqrt(pow(x[a]-x[b],2)+pow(y[a]-y[b],2))*sqrt(pow(x[b]-x[c],2)+pow(y[b]-y[c],2))));
}
if(radsum<M_PI*2)printf("NO\n");
else printf("YES\n");
}
}
|
#include<iostream>
using namespace std;
int main() {
double xa, ya, xb, yb, xc, yc, xd, yd;
char c;
while (cin >> xa >> c >> ya >> c >> xb >> c >> yb >> c >> xc >> c >> yc >> c >> xd >> c >> yd) {
double check1, check2;
bool flg = false;
check1 = (yb - ya) - (yc - ya) / (xc - xa) * (xb - xa);
check2 = (yd - ya) - (yc - ya) / (xc - xa) * (xd - xa);
if (check1 * check2 > 0) { //同じ側
flg = true;
}
check1 = (ya - yb) - (yd - yb) / (xd - xb) * (xa - xb);
check2 = (yc - yb) - (yd - yb) / (xd - xb) * (xc - xb);
if (check1 * check2 > 0) { //同じ側
flg = true;
}
if (flg == true) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
|
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
struct point{
double x;
double y;
};
using namespace std;
int ch(point p1, point p2, point p3){
double dx1=p2.x-p1.x, dy1=p2.y-p1.y;
double dx2=p3.x-p1.x, dy2=p3.y-p1.y;
if(dx1*dy2>dx2*dy1)
return 0;
else
return 1;
}
int main(){
point a,b,c,d;
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y)!=EOF){
//scanf("%d,%d,%d,%d,%d,%d,%d,%d",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y);
if(ch(a,c,b)!=ch(a,c,d) && ch(b,d,a)!=ch(b,d,c))
printf("YES\n");
else
printf("NO\n");
}
}
|
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <map>
using namespace std;
#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)
typedef vector<int> vi;
int main()
{
double x[4], y[4];
while(1){
rep(i, 4){
if(scanf("%lf,%lf,", &x[i], &y[i]) == EOF)
return 0;
}
bool ok = true;
bool turn = true;
rep(i, 4){
bool b = (x[(i+1)%4]-x[i])*(y[(i+2)%4]-y[i])-(y[(i+1)%4]-y[i])*(x[(i+2)%4]-x[i]) < 0.0;
if(!i) turn = b;
else if(turn^b){
ok = false;
break;
}
}
puts(ok ? "YES" : "NO");
}
}
|
#include<iostream>
#include<float.h>
using namespace std;
double pos[4][2];
int solve(){
double a, b, c, d;
a = (pos[0][1] - pos[2][1])*(pos[1][0] - pos[0][0]);
a -= (pos[0][0] - pos[2][0])*(pos[1][1] - pos[0][1]);
b = (pos[0][1] - pos[2][1])*(pos[3][0] - pos[0][0]);
b -= (pos[0][0] - pos[2][0])*(pos[3][1] - pos[0][1]);
c = (pos[1][1] - pos[3][1])*(pos[0][0] - pos[1][0]);
c -= (pos[1][0] - pos[3][0])*(pos[0][1] - pos[1][1]);
d = (pos[1][1] - pos[3][1])*(pos[2][0] - pos[1][0]);
d -= (pos[1][0] - pos[3][0])*(pos[2][1] - pos[1][1]);
if(a*b<=0 && c*d<=0){
return true;
}else{
return false;
}
}
int main(){
int i, j;
char comma;
while(cin >> pos[0][0]){
cin >> comma >> pos[0][1];
for(i=1;i<4;i++){
for(j=0;j<2;j++){
cin >> comma >> pos[i][j];
}
}
if(solve()){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}
}
|
#include <iostream>
#include <cstdio>
#include <cmath>
#define PI 3.1415926535898
#define EPS 1e-9
using namespace std;
double calc(double a1,double a2,double b1,double b2){
return acos((a1 * b1 + a2 * b2) / sqrt(a1 * a1 + a2 * a2) / sqrt(b1 * b1 + b2 * b2)) * 180.0 / PI;
}
int main(){
double x1,y1,x2,y2,x3,y3,x4,y4;
while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4) != EOF){
double c1,c2,c3,c4;
c2 = calc(x1 - x2,y1 - y2,x3 - x2,y3 - y2);
c3 = calc(x2 - x3,y2 - y3,x4 - x3,y4 - y3);
c4 = calc(x3 - x4,y3 - y4,x1 - x4,y1 - y4);
c1 = calc(x4 - x1,y4 - y1,x2 - x1,y2 - y1);
if(abs(360.0 - (c1 + c2 + c3 + c4)) <= EPS) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back
struct poi {
db x, y;
poi op -(poi p) {
return {x - p.x, y - p.y};
}
db cross(poi p) {
return x * p.y - y * p.x;
}
}p[4];
db xmul(poi a, poi b, poi c) {
return (b - a).cross(c - a);
}
int main() {
ios :: sync_with_stdio(0);
while(cin >> p[0].x) {
char c; cin >> c >> p[0].y;
for(int i = 1; i < 4; i ++)
cin >> c >> p[i].x >> c >> p[i].y;
int c1 = 0, c2 = 0;
for(int i = 0; i < 4; i ++)
if(xmul(p[i], p[(i + 1) % 4], p[(i + 2) % 4]) > 0)
c1 ++;
else
c2 ++;
cout << (!c1 || !c2 ? "YES" : "NO") << '\n';
}
return 0;
}
|
#include <cstdio>
int main(){
int n,a[100];
while(scanf("%d",&n), n != 0){
for(int i = 0; i < n; i++){
scanf("%d",&a[i]);
}
int c = 0;
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(a[i] > a[j]){
c++;
}
}
}
printf("%d\n",c);
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
vector<int> v(n);
for (int i=0; i<n; ++i) {
cin >> v[i];
}
int res = 0;
for (int i=0; i<n-1; ++i) {
for (int j=0; j<n-1; ++j) {
if (v[j] > v[j+1]) {
swap(v[j], v[j+1]);
res ++;
}
}
}
cout << res << endl;
}
return 0;
}
|
#include<stdio.h>
int n[1000001]={};
int main(){
int N;
int c=0;
while(1){
scanf("%d",&N);
if(N==0)break;
int c=0;
for(int i=0;i<N;i++){
scanf("%d",&n[i]);}
for(int i=0;i<N;i++)
for(int j=N-1;j>i;j--)
{if(n[j]<n[j-1]){int T=n[j];n[j]=n[j-1];n[j-1]=T;c++;}
}
printf("%d\n",c);
for(int i=0;i<N;i++)
n[i]=0;
}
return 0;
}
|
#include<stdio.h>
int BubbleSort(int [],int n);
int main()
{
int n;
int i;
int A[110];
int cnt=0;
while(scanf("%d",&n),n)
{
for(i=0;i < n;i++){
scanf("%d",&A[i]);
}
cnt = BubbleSort(A,n);
printf("%d\n",cnt);
}
return 0;
}
int BubbleSort(int A[],int n)
{
int i,j;
int cnt = 0;
int temp;
for(i=0;i < n;i++){
for(j=n-1;j > i;j--){
if(A[j-1] > A[j]){
temp = A[j-1];
A[j-1] = A[j];
A[j] = temp;
cnt++;
}
}
}
/*for(i=0;i < n;i++){
if(i) printf(" ");
printf("%d",A[i]);
}
printf("\n");
*/
return cnt;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
while (cin >> n, n) {
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[j] < a[i]) {
ans++;
}
}
}
cout << ans << endl;
}
return 0;
}
|
#include<iostream>
using namespace std;
int main(){
int p;
int n[1000000];
while(cin >> p, p){
int ans = 0;
for(int i=0; i < p; i++){
cin >> n[i];
}
for(int i=0; i < p; i++){
for(int j = 0; j < p-i-1; j++){
if(n[j] > n[j+1]){
swap(n[j], n[j+1]);
ans++;
}
}
}
cout << ans << endl;
}
}
|
// 2011/01/12 Tazoe
#include <iostream>
using namespace std;
int main()
{
while(true){
int n;
cin >> n;
if(n==0)
break;
int num[100];
for(int i=0; i<n; i++)
cin >> num[i];
int cnt = 0;
for(int i=n-1; i>=0; i--)
for(int j=0; j<i; j++)
if(num[j]>num[j+1]){
int tmp = num[j];
num[j] = num[j+1];
num[j+1] = tmp;
cnt++;
}
cout << cnt << endl;
}
return 0;
}
|
#include<iostream>
#include<vector>
int main(){
int n;
while (std::cin >> n, n){
std::vector<int>size(n);
for (int i = 0; i < n; i++){
std::cin >> size[i];
}
int cnt=0;
for (int i = 0; i < n; i++){
for (int j = 0; j < n-i-1; j++){
if (size[j]>size[j + 1]){
cnt++;
std::swap(size[j], size[j + 1]);
}
}
}
std::cout << cnt << std::endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define PP(m) REP(i, m.size()) cout << m[i] << endl;
int main() {
int N;
while (cin >> N && N) {
int c=0;
vector<int> arr(N);
REP(i, N) cin >> arr[i];
REP(i, N-1) {
REP(j, N-i-1) {
if (arr[j] > arr[j+1] && arr[j] != arr[j+1]) {
swap(arr[j], arr[j+1]);
c++;
}
}
}
cout << c << endl;
}
return 0;
}
|
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n;
while(cin>>n,n){
int a[100];
for(int i=0;i<n;i++)cin>>a[i];
int cnt=0;
for(int i=n-1;i>0;i--)
for(int j=0;j<i;j++)
if(a[j]>a[j+1]){
swap(a[j],a[j+1]);
cnt++;
}
cout<<cnt<<endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(){
int n;
while(cin >>n){
if(n==0)
break;
int a[n];
for(int i=0;i<n;i++)
cin >> a[i];
int time=0;
for(int i=0;i<n-1;i++){
for(int j=0;j<n-i-1;j++){
if(a[j]>a[j+1]){
int tmp;
tmp=a[j];
a[j]=a[j+1];
a[j+1]=tmp;
time++;
}
}
}
cout << time << endl;
}
}
|
#include <iostream>
using namespace std;
int main(){
int num;
int n[100]={0};
while(cin >> num){
if(num==0)break;
for(int i=0;i<num;++i) cin >> n[i];
int count=0;
for(int i=0;i<num-1;++i){
for(int j=num-1;j>i;--j){
if(n[j]<n[j-1]){
int tmp = n[j];
n[j]=n[j-1];
n[j-1]=tmp;
++count;
}
}
}
cout << count << "\n";
}
return 0;
}
|
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
int n,t;
while(cin >> n && n){
int a[n];
int r=0;
for(int i=0;i<n;i++){
cin >> a[i];
}
for(int i=n-1;i>0;i--){
for(int j=1;j<=i;j++){
if(a[j-1]>a[j]){
swap(a[j-1],a[j]);
r++;
}
}
}
cout << r << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<int> list;
int x,n,i,s,sum;
while(1){
cin >> n;
if(n==0){break;}
for(i=0;i<n;i++){
cin >> x;
list.push_back(x);
}
sum=0;
i=0;
for(int j=0; j<list.size()-1; j++){
for(i=0; i<list.size()-1; i++){
if(list[i]>list[i+1]){
s=list[i];
list[i]=list[i+1];
list[i+1]=s;
sum++;
}
}
}
cout << sum << endl;
list.clear();
}
}
|
#include <iostream>
#include <vector>
#include <algorithm> // require sort next_permutation etc.
//#include <fstream> // require freopen
using namespace std;
int main()
{
// cut here before submit
// freopen ("testcase.bb", "r", stdin );
int n, m;
while (cin >> n && n ){
vector <int> a(n);
int res = 0;
int i,j;
for (i = 0; i < n; ++i ) {
cin >> a[i];
} // /end for
for (i = 0; i < n; ++i ) {
for (j = 0; j < n - i - 1; ++j ) {
if (a[j] > a[j+1] ) {
swap (a[j], a[j+1] );
++res;
} // end for
} // end for
} // end for
cout << res << endl;
} // end loop
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.