HDU 4380 Farmer Greedy calculation ry + bitset

Source: Internet
Author: User

HDU 4380 Farmer Greedy calculation ry + bitset

Enumerative straight lines. If a point in a straight line is left or right, You can compress a number and use bitset to record it.

Then the triangle is three bitsets & bit


#include 
 
  #include 
  
   #include 
   
    #include using namespace std;typedef long long ll;const int N = 101;const int M = 1005;bitset
    
      b1[N*N], b2[N*N];int x[N], y[N], px[M], py[M];bool check(int i, int j, int k) {if(x[i] != x[j]) {double yy = (double)(y[i] - y[j]) / (x[i] - x[j]) * (x[k] - x[i]) + y[i];if(y[k] >= yy) return true;else return false;} else {  if(x[k] >= x[i])return true;else return false;}}void put(bitset
     
       x) {for(int i = 0; i < M; i ++) {if(x[i]) printf("%d ", i);}puts("*");}int main() {int n, m, cas = 0;while(~scanf("%d%d", &n, &m)) {for(int i = 0; i < n; i ++) {scanf("%d%d", &x[i], &y[i]);}for(int i = 0; i < m; i ++) {scanf("%d%d", &px[i], &py[i]);}for(int i = 0; i < n; i ++) {for(int j = i+1; j < n; j ++) {for(int k = 0; k < m; k ++) {//printf("%d %d  ", i, j);if(x[i] != x[j]) {double yy = (double)(y[i] - y[j]) / (x[i] - x[j]) * (px[k] - x[i]) + y[i];if(py[k] == yy) {b1[i*n+j].set(k);b2[i*n+j].set(k);}else if(py[k] > yy) {b1[i*n+j].set(k);//printf("u1-%d", k);} else {b2[i*n+j].set(k);//printf("d1-%d", k);}} else {if(px[k] == x[i]) {b1[i*n+j].set(k);b2[i*n+j].set(k);}else if(px[k] > x[i])  {b1[i*n+j].set(k);//printf("u2-%d", k);} else {b2[i*n+j].set(k);//printf("d2-%d", k);}}//puts("");}//printf("  %d %d %d %d\n", i, j, b1[i*n+j].count(), b2[i*n+j].count());}}bitset
      
        tmp(0);int ans = 0;for(int i = 0; i < n; i ++) {for(int j = i+1; j < n; j ++) {for(int k = j+1; k < n; k ++) {if(check(i, j, k)) {tmp = b1[i*n+j];//printf("UU1 ");//put(b1[i*n+j]);}else {tmp = b2[i*n+j];//put(b2[i*n+j]);}if(check(i, k, j)) {tmp &= b1[i*n+k];//printf("UU2 ");//put(b1[i*n+k]);}else {tmp &= b2[i*n+k];//put(b2[i*n+k]);}if(check(j, k, i)) {tmp &= b1[j*n+k];//printf("UU3 ");//put(b1[j*n+k]);}else {tmp &= b2[j*n+k];//put(b2[j*n+k]);}//printf("***%d %d %d %d\n", i, j, k, tmp.count());if(tmp.count() & 1) ans ++;}}}printf("Case %d: %d\n", ++cas, ans);for(int i = 0; i < n*n; i ++) {b1[i].reset();b2[i].reset();}}return 0;}/*3 10 00 100100 00 03 10 00 100100 050 503 10 00 100100 0100 03 10 00 100100 00 -14 40 00 100100 0-2 500 00 100100 0-1 50*/
      
     
    
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.