http://codeforces.com/contest/755/problem/D

// 我也觉得非平面图不能用欧拉公式,但是也能过,不知道为什么。求大佬留言。

这题其实就是平面图,因为它有很多个交点。中途的交点使得图的阶数变大了

所以我的思路就是求出V、E、然后解出F。V - E + F = 2

其中每连接一条边,增加的交点就是其路径上的点被多少次经过。(不包括自己端点)

这个可以用BIT维护下。

然后当k > n - k的时候,需要反向一下,因为这样其实就相当于镜面对称一下而已,不然会wa的。

比如5 3 的时候,会翻车

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e6 + ;
LL c[maxn];
int n, k;
int lowbit(int x) {
return x & (-x);
}
void add(int pos, int val) {
while (pos <= n) {
c[pos] += val;
pos += lowbit(pos);
}
}
LL query(int pos) {
LL ans = ;
while (pos > ) {
ans += c[pos];
pos -= lowbit(pos);
}
return ans;
}
void work() {
scanf("%d%d", &n, &k);
int be = ;
LL e = n;
LL v = n;
k = min(k, n - k); //这个是必须的,试试5 3 就知道
for (int i = ; i <= n; ++i) {
int from = be;
int to = be + k;
if (to > n) {
to -= n;
LL addv = query(to - );
if (from != n) {
addv += query(n) - query(from);
}
e += addv;
e += addv + ;
v += addv;
printf("%I64d ", - v + e - );
add(from, );
add(to, );
be = to;
} else {
LL addv = query(to - ) - query(from);
e += addv;
e += addv + ;
v += addv;
printf("%I64d ", - v + e - );
add(from, );
add(to, );
be = to;
}
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

D. PolandBall and Polygon BIT + 欧拉公式的更多相关文章

  1. codeforces 755D. PolandBall and Polygon

    D. PolandBall and Polygon time limit per test 4 seconds memory limit per test 256 megabytes input st ...

  2. 【codeforces 755D】PolandBall and Polygon

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【树状数组】Codeforces Round #755 D. PolandBall and Polygon

    http://codeforces.com/problemset/problem/755/D 每次新画一条对角线的时候,考虑其跨越了几条原有的对角线. 可以用树状数组区间修改点查询来维护多边形的顶点. ...

  4. Codeforces 755D:PolandBall and Polygon(思维+线段树)

    http://codeforces.com/problemset/problem/755/D 题意:给出一个n正多边形,还有k,一开始从1出发,向第 1 + k 个点连一条边,然后以此类推,直到走完 ...

  5. codeforces 755D. PolandBall and Polygon(线段树+思维)

    题目链接:http://codeforces.com/contest/755/problem/D 题意:一个n边形,从1号点开始,每次走到x+k的位置如果x+k>n则到x+k-n的位置,问每次留 ...

  6. CodeForces 755D PolandBall and Polygon ——(xjbg)

    每次连线,起点和终点之间,每一个被点亮的点,这些点都能连出去两条线,因此可以增加的块数+2(1这个点除外,因为只有连出的点没有连进的点),计算起点和终点之间有几个点被点亮即可,然后1这个点特判一下.感 ...

  7. cf 755D. PolandBall and Polygon

    题意:把一个多边形往里面连对角线,然后问每次添加多边形被划分为几个部分 产生的部分就是新加对角线与原有对角线相交条数+1,用线段树(大雾)维护一下. #include<bits/stdc++.h ...

  8. (第八场)G Counting regions 【欧拉公式】

    题目链接:https://www.nowcoder.com/acm/contest/146/G G.Counting regions | 时间限制:1 秒 | 内存限制:128M Niuniu lik ...

  9. [LeetCode] Convex Polygon 凸多边形

    Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...

随机推荐

  1. swool安装

    swoole安装 安装完PHP后,即可安装swoole扩展. swoole扩展下载地址:https://github.com/swoole/swoole-src/releases 尽量选择stable ...

  2. apicloud本地测试安卓测试包安装

    1.liutingdeMacBook-Pro:~ js-lt$ which adb 2.liutingdeMacBook-Pro:~ js-lt$ ls 3.liutingdeMacBook-Pro: ...

  3. iOS 枚举写法

    1.第一种 typedef enum { kPRStateNormal = 0, kPRStatePulling = 1, kPRStateLoading = 2, kPRStateHitTheEnd ...

  4. liunx 定时执行 php文件

    which php    寻找php路径

  5. dl以及dt,dd,以及table的tr,th,td最清楚分析

    1,定义:<dl> <dt> <dd>是一组合标签,使用了dt dd最外层就必须使用dl包裹,此组合标签我们也又叫表格标签,与table表格类似组合标签,故名我们也 ...

  6. U3D脚本开发基础

    1.MonoBehaviour类,定义了对各种特定事件的脚本响应函数.这些函数均以On做开头. 2.U3D中常用的组件及对应变量名如下: Transform(transform),Rigidbody( ...

  7. L5,no wrong numbers

    expressions: up to now,到现在为止 a great many,数量很大 in a way,在某种意义上说   words: burn,vt燃烧,vi烧毁,n灼烧 obtain,v ...

  8. angularjs ng-switch

    <p> <a href="#" ng-click="toggle()">Toggle Section</a> </p& ...

  9. ZABBIX自定义用户KEY与参数USERPARAMETERS监控脚本输出

    zabbix在模板中预定义了一些key,但通常情况,并不能满足我们的需求.幸运的是zabbix提供了自定义key的方法,因此我们可以灵活的监控各种我们想要监控的数据. 定义配置文件 通过yum安装的z ...

  10. Struts2语法--Ognl

    OGNL: Object Graph Navigation Language index.jsp: <body> 访问属性 <a href="<%=contextPa ...