标签:
1 #include <algorithm> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <queue> 6 #include <map> 7 #include <set> 8 #include <ctime> 9 #include <cmath> 10 #include <iostream> 11 #define pi acos(-1.) 12 using namespace std; 13 typedef long long ll; 14 const int int_inf = 0x3f3f3f3f; 15 const ll ll_inf = 1ll << 62; 16 const int INT_INF = (int)((1ll << 31) - 1); 17 const int mod = 1e6 + 7; 18 const double double_inf = 1e30; 19 typedef unsigned long long ul; 20 #pragma comment(linker, "/STACK:102400000,102400000") 21 #define max(a, b) ((a) > (b) ? (a) : (b)) 22 #define min(a, b) ((a) < (b) ? (a) : (b)) 23 #define mp make_pair 24 #define st first 25 #define nd second 26 #define keyn (root->ch[1]->ch[0]) 27 #define lson (u << 1) 28 #define rson (u << 1 | 1) 29 #define pii pair<int, int> 30 #define pll pair<ll, ll> 31 #define pb push_back 32 #define type(x) __typeof(x.begin()) 33 #define foreach(i, j) for(type(j)i = j.begin(); i != j.end(); i++) 34 #define FOR(i, s, t) for(int i = s; i <= t; i++) 35 #define ROF(i, t, s) for(int i = t; i >= s; i--) 36 #define dbg(x) cout << x << endl 37 #define dbg2(x, y) cout << x << " " << y << endl 38 #define clr(x, i) memset(x, (i), sizeof(x)) 39 #define maximize(x, y) x = max((x), (y)) 40 #define minimize(x, y) x = min((x), (y)) 41 inline int readint(){ 42 bool neg = 0; char ch, t[11]; 43 int k = 0; 44 while((ch = getchar()) == ‘ ‘ || ch == ‘\n‘) ; 45 neg = ch == ‘-‘; 46 ch == ‘-‘ ? neg = 1 : t[k++] = ch; 47 while((ch = getchar()) >= ‘0‘ && ch <= ‘9‘) t[k++] = ch; 48 int x = 0, y = 1; 49 while(k) x += (t[--k] - ‘0‘) * y, y *= 10; 50 return neg ? -x : x; 51 } 52 53 inline int readstr(char *s){ 54 char ch; 55 int len = 0; 56 while((ch = getchar()) == ‘ ‘ || ch == ‘\n‘) ; 57 if(ch == EOF) return 0; 58 *(s++) = ch, ++len; 59 while((ch = getchar()) != ‘ ‘ && ch != ‘\n‘ && ch != EOF) *(s++) = ch, ++len; 60 *s = ‘\0‘; 61 return len; 62 } 63 64 inline void writestr(const char *s){ 65 while(*s != ‘\0‘) putchar(*(s++)); 66 putchar(‘\n‘); 67 } 68 69 inline void writeint(int num){ 70 if(!num){ 71 putchar(‘0‘), putchar(‘\n‘); 72 return; 73 } 74 if(num < 0) num = -num, putchar(‘-‘); 75 char buf[15]; 76 int k = 0; 77 while(num) buf[k++] = num % 10, num /= 10; 78 ROF(i, k - 1, 0) putchar(buf[i] + ‘0‘); 79 putchar(‘\n‘); 80 } 81 class cmpt{ 82 public: 83 bool operator () (const int &x, const int &y) const{ 84 return x > y; 85 } 86 }; 87 int Rand(int x, int o){ 88 //if o set, return [1, x], else return [0, x - 1] 89 int tem = (int)((double)rand() / RAND_MAX * x) % x; 90 return o ? tem + 1 : tem; 91 } 92 93 void data_gen(){ 94 freopen("in.txt", "w", stdout); 95 int n = 80, y = 4000; 96 printf("%d %d\n", n, y); 97 int operand; 98 srand(time(0)); 99 FOR(i, 1, y){ 100 operand = rand() % 2; 101 if(operand){ 102 printf("Q "); 103 int num = rand() % 13 + 1; 104 printf("%d ", num); 105 FOR(j, 1, num){ 106 int tem = Rand(n, 0); 107 printf("%d ", tem); 108 } 109 printf("\n"); 110 }else{ 111 printf("I "); 112 int ok = rand() % 2; 113 if(ok){ 114 printf("%d %d\n", Rand(n, 0), Rand(1 << 20, 0)); 115 }else{ 116 printf("%d %d %d\n", Rand(n, 0), Rand(n, 0), Rand(1 << 20, 0)); 117 } 118 } 119 } 120 } 121 122 struct cmpx{ 123 bool operator () (int x, int y) { return x > y; } 124 }; 125 int debug = 0; 126 int dx[] = {-1, 1, 0, 0}; 127 int dy[] = {0, 0, -1, 1}; 128 //------------------------------------------------------------------------- 129 const int maxn = 1e4 + 10; 130 pii buf[maxn]; 131 int s, r, w, p; 132 set<pii> S; 133 pii pdt[maxn]; 134 pair<pii, pii> walls[20]; 135 136 ll Cross(pii x, pii y){ 137 return (ll)x.st * y.nd - (ll)x.nd * y.st; 138 } 139 140 int Dif(ll x, ll y){ 141 return !(x > 0 && y > 0 || x < 0 && y < 0); 142 } 143 pii operator - (pii x, pii y) { return mp(y.st - x.st, y.nd - x.nd); } 144 145 int Intersect(pair<pii, pii> _wall, pii x, pii y){ 146 pii a1 = _wall.st, a2 = _wall.nd; 147 pii b1 = x, b2 = y; 148 ll c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1); 149 ll c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1); 150 //dbg2(c1, c2), dbg2(c3, c4); 151 return Dif(c1, c2) && Dif(c3, c4); 152 } 153 154 //------------------------------------------------------------------------- 155 int main(){ 156 //data_gen(); return 0; 157 debug = 1; 158 /////////////////////////////////////////////////////////////////////////////////////////////////////////////// 159 if(debug) freopen("in.txt", "r", stdin); 160 //freopen("out.txt", "w", stdout); 161 int T = readint(); 162 while(T--){ 163 s = readint(), r = readint(), w = readint(), p = readint(); 164 S.clear(); 165 FOR(i, 1, s){ 166 int x = readint(), y = readint(); 167 S.insert(mp(x, y)); 168 } 169 FOR(i, 1, w){ 170 int x = readint(), y = readint(); 171 walls[i].st = mp(x, y); 172 x = readint(), y = readint(); 173 walls[i].nd = mp(x, y); 174 } 175 FOR(i, 1, p){ 176 int x = readint(), y = readint(); 177 pdt[i] = mp(x, y); 178 } 179 FOR(i, 1, p){ 180 int tem = 0; 181 FOR(j, -r, r) FOR(k, -r, r){ 182 int nx = pdt[i].st + j, ny = pdt[i].nd + k; 183 if(S.find(mp(nx, ny)) == S.end()) continue; 184 int dist = j * j + k * k; 185 if(dist > r * r) continue; 186 int res = 0; 187 FOR(u, 1, w) if(Intersect(walls[u], mp(nx, ny), pdt[i])) ++res; 188 if(res > r) continue; 189 int tmp = r - res; 190 if(dist > tmp * tmp) continue; 191 buf[tem++] = mp(nx, ny); 192 } 193 printf("%d", tem); 194 FOR(u, 0, tem - 1) printf(" (%d,%d)", buf[u].st, buf[u].nd); 195 putchar(‘\n‘); 196 } 197 } 198 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 199 return 0; 200 } 201 //https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3919 202 //WA 203 //http://paste.ubuntu.com/18381653/
标签:
原文地址:http://www.cnblogs.com/astoninfer/p/5638781.html