• G. The Morning Star


    Problem - G - Codeforces

    思路:想了挺长时间的,一直没想到一个简便的方法在瞎搞。我们发现对于某个点来说,其他的点如果能够跟他匹配,那么一定在这8个方向上,而同时这8个方向其实对应这4条直线,假设点为(x1,y1),那么直线为x=x1,y=y1,y=x+y1-x1,y=-x+x1+y1,那么在求能够跟当前点匹配的点时,只需要看一下在这四条直线上的点的数量,假设为a,b,c,d,那么产生的贡献就是a-1+b-1+c-1+d-1,同时我们还需要考虑会不会重复,就是一个点会不会跟一个点匹配两次,因为保证了没有重复点,所以前两条直线是不会重复的,那么后两条直线也是不会重复的,只有当x1=0,y1=0时后两个直线重复,但是在算贡献是一定不会同时添加

    1. // Problem: G. The Morning Star
    2. // Contest: Codeforces - Codeforces Round 886 (Div. 4)
    3. // URL: https://codeforces.com/contest/1850/problem/G
    4. // Memory Limit: 256 MB
    5. // Time Limit: 2000 ms
    6. #include
    7. #include
    8. #include
    9. #define fi first
    10. #define se second
    11. #define i128 __int128
    12. using namespace std;
    13. typedef long long ll;
    14. typedef double db;
    15. typedef pair<int,int> PII;
    16. const double eps=1e-7;
    17. const int N=5e5+7 ,M=5e5+7, INF=0x3f3f3f3f,mod=1e9+7,mod1=998244353;
    18. const long long int llINF=0x3f3f3f3f3f3f3f3f;
    19. inline ll read() {ll x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
    20. while(c>='0'&&c<='9') {x=(ll)x*10+c-'0';c=getchar();} return x*f;}
    21. inline void write(ll x) {if(x < 0) {putchar('-'); x = -x;}if(x >= 10) write(x / 10);putchar(x % 10 + '0');}
    22. inline void write(ll x,char ch) {write(x);putchar(ch);}
    23. void stin() {freopen("in_put.txt","r",stdin);freopen("my_out_put.txt","w",stdout);}
    24. bool cmp0(int a,int b) {return a>b;}
    25. template<typename T> T gcd(T a,T b) {return b==0?a:gcd(b,a%b);}
    26. template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
    27. void hack() {printf("\n----------------------------------\n");}
    28. int T,hackT;
    29. int n,m,k;
    30. PII w[N];
    31. void solve() {
    32. n=read();
    33. for(int i=1;i<=n;i++) w[i].fi=read(),w[i].se=read();
    34. ll res=0;
    35. map<int,int> a,b,c,d;
    36. for(int i=1;i<=n;i++) {
    37. a[w[i].fi]++;
    38. b[w[i].se]++;
    39. c[w[i].fi+w[i].se]++;
    40. d[w[i].se-w[i].fi]++;
    41. }
    42. for(int i=1;i<=n;i++) {
    43. a[w[i].fi]--;
    44. b[w[i].se]--;
    45. c[w[i].fi+w[i].se]--;
    46. d[w[i].se-w[i].fi]--;
    47. res+=a[w[i].fi]+b[w[i].se]+c[w[i].fi+w[i].se]+d[w[i].se-w[i].fi];
    48. }
    49. printf("%lld\n",res*2);
    50. }
    51. int main() {
    52. // init();
    53. // stin();
    54. // ios::sync_with_stdio(false);
    55. scanf("%d",&T);
    56. // T=1;
    57. while(T--) hackT++,solve();
    58. return 0;
    59. }

  • 相关阅读:
    【CV】树莓派+OpenCV-python解决摄像头分辨率及帧率过低无法调整问题
    springboot使用SSE
    一起看看Python中的迭代器&生成器
    Spring 事务
    C#winform导出DataGridView数据到Excel表
    Cesium+Shader:两种动态墙效果
    Langchain-Chatchat项目:4.1-P-Tuning v2实现过程
    剑指 Offer 10- II. 青蛙跳台阶问题
    百万数据直接返回,高性能量化数据库Arctic,基于mongo的列存引擎
    shiro721反序列化漏洞(CVE-2019-12422)原理与漏洞复现和利用(保姆级的详细教程)
  • 原文地址:https://blog.csdn.net/zzzyyzz_/article/details/132766145