20200727T2 【NOIP2015模擬10.30晚】走路
阿新 • • 發佈:2020-07-27
Description
3 3 2 4 4 3 4 3 6 4
2 2 2
一個人在t[i]之前不存在, 在走到f[i]之後消失.
Solution
code
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #include<queue> 7 #include<vector> 8 #include<stack> 9#include<set> 10 #include<deque> 11 #include<map> 12 using namespace std; 13 14 template <typename T> void read(T &x) { 15 x = 0; int f = 1; char c; 16 for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') f = -f; 17 for (; c >= '0' && c <= '9'; c = getchar()) x = 10 * x + c - '0' ; 18 x *= f; 19 } 20 template <typename T> void write(T x){ 21 if (x < 0) putchar('-'), x = -x; 22 if (x > 9) write(x / 10); 23 putchar(x % 10 + '0'); 24 } 25 template <typename T> void writeln(T x) { write(x); putchar('\n'); } 26 template <typename T> voidwritesn(T x) { write(x); putchar(' '); } 27 28 #define int long long 29 #define inf 100000 30 #define next net 31 #define P 9999991 32 #define N 1010 33 #define mid ((l+r)>>1) 34 #define lson (o<<1) 35 #define rson (o<<1|1) 36 #define R register 37 #define debug puts("zxt") 38 39 int n, ans[N ]; 40 struct node{ 41 double k, b; 42 int st, ed, num ; 43 }e[N ]; 44 inline bool cmp(node a, node b) 45 { 46 return a.st < b.st; 47 } 48 inline bool check(int x, int y) 49 { 50 if(e[x].ed < e[y].st) return false; 51 double t1 = (e[x].k * 1.0 * e[y].st + e[x].b - e[y].k * 1.0 * e[y].st - e[y].b); 52 double t2 = (e[x].k * 1.0 * min(e[x].ed, e[y].ed) + e[x].b - e[y].k * 1.0 * min(e[x].ed, e[y].ed) - e[y].b); 53 return t1 * t2 <= 0; 54 } 55 signed main() 56 { 57 //freopen("walk.in","r",stdin); 58 //freopen("walk.out","w",stdout); 59 read(n); 60 for(R int i = 1, t, s, f; i <= n; i++) 61 { 62 read(t); read(s); read(f); 63 e[i].num = i; 64 e[i].st = t; 65 e[i].ed = t + abs(f - s); 66 if(f - s < 0) e[i].k = -1.0; 67 else e[i].k = 1.0; 68 e[i].b = 1.0 * s - 1.0 * t * e[i].k; 69 } 70 sort(e + 1, e + n + 1, cmp); 71 for(R int i = 1; i <= n; i++) 72 for(R int j = i + 1; j <= n; j++) 73 { 74 if(check(i, j)) ans[e[i].num ]++, ans[e[j].num ]++; 75 } 76 for(R int i = 1; i <= n; i++) writesn(ans[i]); 77 return 0; 78 }