• CF755D 【PolandBall and Polygon】


    题意:

    给你一个n边行,每次让你将x与(x+k)%n的点连一条边,每次询问该多边形内面积被划分成了几块

    分析:

    我们发现这个输出很有规律,但是规律好像不是很好找。

    于是我们考虑其他方法。

    根据样例分析的图画,我们发现:

    1.前两幅图只对答案做出了1的贡献

    2.第3幅图对答案做出了2的贡献,且他连出的边与边(1,3)有交点;

    3.图4,5都对答案做出了3的贡献,且有两个交点;

    根据这个发现,我们大胆的推断出了结论:每条边对答案的贡献是与他的交点的个数+1

    那么怎么算交点个数呢?

    题目给了我们一个台阶,他告诉我们n与k互质且k不变,

    于是不会出现重边或边包含边的问题,于是我们的问题就转化成了维护x到(x+k)%n中的点延伸出的边的数量(这些边必与本边相交),这个可以通过任何一种数据结构维护,like树状数组

    注意两个细节:

    1.k = min(k, n - k)

    2.long long

    分类讨论搞一下就AC了吧。

    代码:

      1 #include <map>
      2 #include <set>
      3 #include <cmath>
      4 #include <ctime>
      5 #include <queue>
      6 #include <stack>
      7 #include <vector>
      8 #include <bitset>
      9 #include <cstdio>
     10 #include <cctype>
     11 #include <string>
     12 #include <cstring>
     13 #include <cassert>
     14 #include <climits>
     15 #include <cstdlib>
     16 #include <iostream>
     17 #include <algorithm>
     18 #include <functional>
     19 using namespace std ;
     20 
     21 #define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
     22 #define Rep(i, a, b) for (int (i) = (a) - 1; (i) < (b); (i)++)
     23 #define REP(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
     24 #define clr(a) memset(a, 0, sizeof(a))
     25 #define Sort(a, len, cmp) sort(a + 1, a + len + 1, cmp)
     26 #define ass(a, sum) memset(a, sum, sizeof(a))
     27 
     28 #define ls ((rt) << 1)
     29 #define rs ((rt) << 1 | 1)
     30 #define lowbit(x) (x & -x)
     31 #define mp make_pair
     32 #define pb push_back
     33 #define fi first
     34 #define se second
     35 #define endl '
    '
     36 #define ENDL cout << endl
     37 #define SZ(x) ((int)x.size())
     38 
     39 typedef long long ll ;
     40 typedef unsigned long long ull ;
     41 typedef vector <int> Vi ;
     42 typedef pair <int, int> Pii ;
     43 typedef pair <ll, ll> Pll ;
     44 typedef map <int, int> mii ;
     45 typedef map <string, int> msi ;
     46 typedef map <ll, ll> mll ;
     47 
     48 const int N = 1000100 ;
     49 const double eps = 1e-8 ;
     50 const int iinf = INT_MAX ;
     51 const ll linf = 2e18 ;
     52 const double dinf = 1e30 ;
     53 const int MOD = 1000000007 ;
     54 
     55 inline int read(){
     56     int X = 0, w = 0 ;
     57     char ch = 0 ;
     58     while (!isdigit(ch)) { w |= ch == '-' ; ch = getchar() ; }
     59     while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar() ;
     60     return w ? - X : X ;
     61 }
     62 
     63 void write(int x){
     64      if (x < 0) putchar('-'), x = - x ;
     65      if (x > 9) write(x / 10) ;
     66      putchar(x % 10 + '0') ;
     67 }
     68 
     69 void print(int x) {
     70     cout << x << endl ;
     71     exit(0) ;
     72 }
     73 
     74 void PRINT(string x) {
     75     cout << x << endl ;
     76     exit(0) ;
     77 }
     78 
     79 void douout(double x){
     80      printf("%lf
    ", x + 0.0000000001) ;
     81 }
     82 
     83 int n, k, now, to ;
     84 ll ans ;
     85 int bit[N] ;
     86 
     87 void add(int a, int x) {
     88     for (; a <= n; a += lowbit(a)) bit[a] += x ;
     89 }
     90 
     91 int sum(int a) {
     92     int res = 0 ;
     93     for (; a; a -= lowbit(a)) res += bit[a] ;
     94     return res ;
     95 }
     96 
     97 signed main(){
     98     scanf("%d%d", &n, &k) ;
     99     k = min(k, n - k) ;
    100     now = 1 ;
    101     ans = 1 ;
    102     for (int i = 1; i <= n; i++) {
    103         to = now + k ;
    104         ans++ ;
    105         if (to > n) {
    106             to -= n ;
    107             ans += sum(n) - sum(now) + sum(to - 1) ;
    108         }
    109         else {
    110             ans += sum(to - 1) - sum(now) ;
    111         }
    112         add(now, 1) ;
    113         add(to, 1) ;
    114         now = to ;
    115         printf("%lld ", ans) ;
    116     }
    117 }
    AC CODE
    加油ヾ(◍°∇°◍)ノ゙
  • 相关阅读:
    c++指向数组的指针,数组指针
    c#和c++互操作(平台调用相关)
    LA和TA
    RSCP RSRP RSRQ
    HARQ(Hybrid Automatic Repeat Request ) 混合自动重传请求
    传输层的几个部分的ALCAP、SSCOP、MTP3-B、SCCP、SAAL、SCCF、STC、IP、UDP、GTPU
    SSCOP Service Specific Connection Oriented Protocol 业务特定面向连接协议
    SSCF-UNI
    PCRF、PCEF、PCC(转帖)
    LTE中的几个概念——LTE,SAE,EPC,EPS
  • 原文地址:https://www.cnblogs.com/harryhqg/p/10025728.html
Copyright © 2020-2023  润新知