Submission #1303228


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl; 
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v)            for (auto i : v)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
#define pb(x)                 push_back(x)
#define bp(x)                 __builtin_popcount(x)
#define mp(x, y)              make_pair((x), (y))
#define fi                    first
#define se                    second
#define setp(x)               setprecision(x)
#define mset(m, v)            memset(m, v, sizeof(m))
#define sz(x)                 (int)(x.size())
static const int INF        = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD        = 1000000007;
static const double PI      = 3.14159265358979;

//#define int                   long long

typedef vector<double>        vd;
typedef vector<string>        vs;
typedef vector<bool>          vb;
typedef vector<int>           vi;
typedef pair<int, int>        pii;
typedef vector<pii>           vpii;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int _x; scanf("%d", &_x); return _x; }
long long lin() {long long _x; scanf("%lld", &_x); return _x; };

//bool intersect(int ax, int ay, int bx, int by, int cx, int cy, int dx, int dy){
//	long long ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
//	long long tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
//	long long tc = (ax - bx) * (cy - ay) + (ay - dy) * (ax - cx);
//	long long td = (ax - bx) * (dy - ay) + (ay - dy) * (ax - dx);
//        return ta * tb < 0LL && tc * td < 0LL;
//}

bool intersect(int ax,int ay,int bx,int by,int cx,int cy,int dx,int dy){
	long long ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	long long tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	long long tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	long long td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	if(ta*tb<0LL&&tc*td<0LL)return true;
	else return false;
}

signed main() { 
        int ax, ay, bx, by;
        cin >> ax >> ay >> bx >> by;
        int n;
        cin >> n;
        vi x(n), y(n);
        rep(i, n) cin >> x[i] >> y[i];
        int ans = 0;
        rep(i, n) ans += intersect(ax, ay, bx, by, x[i], y[i], x[(i + 1) % n], y[(i + 1) % n]);
        cout << ans / 2 + 1 << endl;
        return 0;
}               

Submission Info

Submission Time
Task D - 一刀両断
User KokiYmgch
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2832 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int in()’:
./Main.cpp:35:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 int in() { int _x; scanf("%d", &_x); return _x; }
                                    ^
./Main.cpp: In function ‘long long int lin()’:
./Main.cpp:36:50: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 long long lin() {long long _x; scanf("%lld", &_x); return _x; };
                                                  ^

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 32
Set Name Test Cases
All 00_sample_00.txt, 00_sample_01.txt, 10_rand_00.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 10_rand_06.txt, 10_rand_07.txt, 10_rand_08.txt, 10_rand_09.txt, 10_rand_10.txt, 10_rand_11.txt, 10_rand_12.txt, 10_rand_13.txt, 10_rand_14.txt, 10_rand_15.txt, 10_rand_16.txt, 10_rand_17.txt, 10_rand_18.txt, 10_rand_19.txt, 10_rand_20.txt, 10_rand_21.txt, 10_rand_22.txt, 10_rand_23.txt, 10_rand_24.txt, 10_rand_25.txt, 10_rand_26.txt, 10_rand_27.txt, 10_rand_28.txt, 10_rand_29.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 256 KB
00_sample_01.txt AC 1 ms 256 KB
10_rand_00.txt AC 1 ms 256 KB
10_rand_01.txt AC 1 ms 256 KB
10_rand_02.txt AC 1 ms 256 KB
10_rand_03.txt AC 1 ms 256 KB
10_rand_04.txt AC 1 ms 256 KB
10_rand_05.txt AC 1 ms 256 KB
10_rand_06.txt AC 1 ms 256 KB
10_rand_07.txt AC 1 ms 256 KB
10_rand_08.txt AC 1 ms 256 KB
10_rand_09.txt AC 1 ms 256 KB
10_rand_10.txt AC 1 ms 256 KB
10_rand_11.txt AC 1 ms 256 KB
10_rand_12.txt AC 1 ms 256 KB
10_rand_13.txt AC 1 ms 256 KB
10_rand_14.txt AC 1 ms 256 KB
10_rand_15.txt AC 1 ms 256 KB
10_rand_16.txt AC 1 ms 256 KB
10_rand_17.txt AC 1 ms 256 KB
10_rand_18.txt AC 1 ms 256 KB
10_rand_19.txt AC 1 ms 256 KB
10_rand_20.txt AC 1 ms 256 KB
10_rand_21.txt AC 1 ms 256 KB
10_rand_22.txt AC 1 ms 256 KB
10_rand_23.txt AC 1 ms 256 KB
10_rand_24.txt AC 1 ms 256 KB
10_rand_25.txt AC 1 ms 256 KB
10_rand_26.txt AC 1 ms 256 KB
10_rand_27.txt AC 1 ms 256 KB
10_rand_28.txt AC 1 ms 256 KB
10_rand_29.txt AC 1 ms 256 KB