codeforces1549 F1 - Gregor and the Odd Cows (Easy)(皮克公式)

皮克公式:求格点多边形面积
A = B 2 + I − 1 A=\frac B 2+I-1 A=2B+I1
其中
A:area 面积
B:boundary 边界上整点的个数
I:interior 多边形内部点的个数

对于两个整数点 ( x 1 , y 1 ) , ( x 2 , y 2 ) (x_1,y_1),(x_2,y_2) (x1,y1),(x2,y2)来说,它们连线上整点的个数为 gcd ⁡ ( x 2 − x 1 , y 2 − y 1 ) \gcd(x_2-x_1,y_2-y_1) gcd(x2x1,y2y1)


考虑下面的式子 2 A = B + 2 ( I − 1 ) 2A=B+2(I-1) 2A=B+2(I1)
对于本题来说,首先由于点的坐标都是偶数,那么任意三点组成的三角形面积一定是偶数,并且由题意得满足条件时 I I I为奇数,那么 2 ( i − 1 ) 2(i-1) 2(i1)一定时4的倍数,同时 2 A 2A 2A也是4的倍数,可以推出B是4的倍数是满足题意的充分必要条件!

由于点的坐标都是偶数点,那么 gcd ⁡ ( x 2 − x 1 , y 2 − y 1 ) [ m o d    4 \gcd(x_2-x_1,y_2-y_1)[\mod4 gcd(x2x1,y2y1)[mod4]只有两种情况即 0 0 0或者 2 2 2

gcd ⁡ ( x 2 − x 1 , y 2 − y 1 ) ≡ { 0 , x 1 ≡ x 2 ( m o d 4 ) and y 1 ≡ y 2 ( m o d 4 ) 2 , else \gcd(x_2-x_1,y_2-y_1)\equiv \begin{cases}0,x_1\equiv x_2\pmod4 \text{and} y_1 \equiv y_2\pmod4\\2,\text{else} \end{cases} gcd(x2x1,y2y1){0,x1x2(mod4)andy1y2(mod4)2,else


太晚了懒得写了,放的dls的代码 p \color{black}\text p p reehs_moorhsum \color{red}\text {reehs\_moorhsum} reehs_moorhsum

#include <bits/stdc++.h>

using namespace std;
using ll=long long;
const int maxn=7005;

int n, x[maxn], y[maxn];
int cnt[10][10], d[maxn][maxn];
ll ans;
pair<int,int> g[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", x + i, y + i);
    cnt[x[i] % 4][y[i] % 4]++;
    g[i] = make_pair(x[i] % 4, y[i] % 4);
  }
  vector<pair<int,int>> p{{0, 0}, {0, 2}, {2, 0}, {2, 2}};
  for (auto x : p)
    for (auto y : p)
      for (auto z : p)
        if (x <= y && y <= z) {
          int d1 = (x == y) ? 0 : 2, d2 = (y == z) ? 0 : 2,
              d3 = (x == z) ? 0 : 2;
          int c1 = cnt[x.first][x.second], c2 = cnt[y.first][y.second], c3 = cnt[z.first][z.second];
          if ((d1 + d2 + d3) % 4 == 0) {
            if (x == y && y == z) {
              ans += (ll)c1 * (c1 - 1) * (c1 - 2) / 6;
            } else if (x == y) {
              ans += (ll)c1 * (c1 - 1) / 2 * c3;
            } else if (y == z) {
              ans += (ll)c1 * c3 * (c3 - 1) / 2;
            } else {
              ans += (ll)c1 * c2 * c3;
            }
          }
        }
  printf("%lld\n", ans);
  /*  for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++)
        d[i][j] = abs(__gcd(x[i] - x[j], y[i] - y[j]));
    int ans2 = 0;
    for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++)
        for (int k = j + 1; k <= n; k++) {
          assert(((d[i][j] + d[j][k] + d[i][k]) % 4 == 0) ==
                 (g[i] == g[j] || g[j] == g[k] || g[k] == g[i]));
          if ((d[i][j] + d[j][k] + d[i][k]) % 4 == 0) {
            ans2++;
          }
        }
    printf("%d\n", ans2);*/
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值