zoukankan      html  css  js  c++  java
  • luogu P4132 [BJOI2012]算不出的等式

    传送门

    以前的题

    当时集训的时候老师连着笑话一起讲的

    这题自己先找规律打表就猜是(p-1)*(q-1)/4

    没有∑套∑ 先把式子分成两个(其实是一样的)

    然后考虑这个式子求和前的每一项 

    对于每一个k求的都是y=q/p*x下的整点数

    然后另一边就是互补的一侧

    (该式两部分分别是一个([p/2],[q/2])方格图主对角线分成的两部分的整点数.)[]表示下取整

    dao一下洛谷的图

    图大概长这样

    由于p,q是质数 所以只有相等的时候会有p个点会少算(边界)

    Code:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<queue>
     5 #define ms(a,b) memset(a,b,sizeof a)
     6 #define rep(i,a,n) for(int i = a;i <= n;i++)
     7 #define per(i,n,a) for(int i = n;i >= a;i--)
     8 #define inf 1000000007
     9 using namespace std;
    10 typedef long long ll;
    11 typedef double D;
    12 #define eps 1e-8
    13 ll read() {
    14     ll as = 0,fu = 1;
    15     char c = getchar();
    16     while(c < '0' || c > '9') {
    17         if(c == '-') fu = -1;
    18         c = getchar();
    19     }
    20     while(c >= '0' && c <= '9') {
    21         as = as * 10 + c - '0';
    22         c = getchar();
    23     }
    24     return as * fu;
    25 }
    26 //head
    27 ll p,q,ans;
    28 int main() {
    29     p = read(),q = read();
    30     ans = (p>>1)*(q>>1);
    31     if(p == q) ans += p>>1;
    32     printf("%lld
    ",ans);
    33     return 0;
    34 }
    View Code
    > 别忘了 总有人在等着你
  • 相关阅读:
    linux 硬件信息
    docker note
    Shell cmd set note
    mysql management note
    scp noneed passwd
    update kernel
    数据包处理过程
    tcp/ip分片
    sockopt note
    Python note
  • 原文地址:https://www.cnblogs.com/yuyanjiaB/p/9893516.html
Copyright © 2011-2022 走看看