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. Spring Boot 系列教程13-注解定时任务

    注解 @Scheduled(cron = "0/5 * * * * ?") 相当于原来的xml版本的如下配置 <task:scheduled ref="schedu ...

  2. runtime基础知识

    看到一篇不错的runtime方面博客: 引言 相信很多同学都听过运行时,但是我相信还是有很多同学不了解什么是运行时,到底在项目开发中怎么用?什么时候适合使用?想想我们的项目中,到底在哪里使用过运行时呢 ...

  3. curl file_get_contents fsockopen

    三种处理的方式:     curl     file_get_contents     fsockopen fsockopen 是比较底层的调用,属于网络系统的socket调用,而curl经过的包装支 ...

  4. AppCompatActivity工具栏的设置(返回操作)

    <android.support.v7.widget.Toolbar android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionB ...

  5. eclipse Dynamic web project 工程目录

    如图,我创建了一个work 的web project,当工程完成之后,部署在服务器上时,整个work工程会被打包成一个war包,如 除了可以在eclipse上运行,工具会帮我们自动部署在服务器上之外, ...

  6. OpenCv的Java,C++开发环境配置

    1.OpenCV 下载及安装配置 opencv的下载地址:http://opencv.org/downloads.html 最新版本:opencv3.0.0 注意:支持的visual studio20 ...

  7. bluehost 邮箱设置问题

    问题描述: e-elitech.com域名,elitechus.com域名均在阿里云注册,en.e-elitech.com解析到bluehost虚拟主机,www.elitechus.com也解析到bl ...

  8. dom4j解析xml实例

    dom4j是一个java的XML API,类似jdom,用来读写XML文件,它性能优异.功能强大和极易使用等特点 所用jar包:dom4j-1.6.1.jar 需要解析的xml文件:people.xm ...

  9. 网页中如何用 CSS 设置打印分页符

    Word 中按 Ctrl + Enter 创建一个分页符,方便打印,其实网页中也可以,用 CSS 的 page-break-after:always;. <p>第 1 页</p> ...

  10. typescript中的工具 tsd

    首先帮微软买个广告:VSCode 实在是太适合我了,感觉写起来无比舒畅,建议有兴趣的可以去试试用vsCode写前端. 最近开始使用ts去构建项目,感觉写起来非常的爽(本人以前接触过c#和java),终 ...