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. coco2d-x CCDirector.h文件中变量*m_pNotificationNode*

    1.在CCDiretor.h中有如下说明 /** This object will be visited after the main scene is visited. This object MU ...

  2. php 批量导入数据的一种思维

    <?php $str="风湿免疫科 消化内科 内分泌科 神经内科 感染内科 心血管内科放疗中心";$arr=explode(' ',$str);$sql="&quo ...

  3. gSoap工具wsdl2h及soapcpp2指令汇总

    gSoap开发包的下载地址http://sourceforge.net/projects/gsoap2,在bin目录下提供了两个工具: 1:wsdl2h:The gSOAP wsdl2h tool i ...

  4. Hibernate的dynamic-insert和dynamic-update的使用

    Hibernate在初始化的时候,默认按照配置为表预定义insert,delete,update,select(by id)的SQL语句放在session中,其中insert,update,selec ...

  5. Jmeter的优点是什么?除了轻量级,它和LoadRunner有什么本质区别

    1.jmeter的架构和loadrunner原理一样,都是通过中间代理,监控和收集并发客户端发出的指令,把他们生成脚本,再发送到应用服务器,再监控服务器反馈结果的一个过程: 2.分布式中间代理功能在j ...

  6. jenkins tags

    List Subversion tags (and more) 参数设置 Tags filter ^((?!_ta_).)*$ 表示不含_ta_ Tags filtertrunk|(tags|bran ...

  7. 转:LoadRunner常用函数列表

    Web相关函数 函    数 功 能 描 述 web_custom_request 用户可以通过该函数自行创建一个HTTP请求的函数 web_image 模拟用户单击图片操作的函数 web_link ...

  8. 使用ADO对象添加、修改、删除数据

    使用ADO对象对数据库中的数据进行添加.修改和删除等操作.首先创建一个ADO类,通过ADO类连接数据库,并打开记录集.例如,使用ADO对象添加.修改.删除数据,程序设计步骤如下:(1)创建一个基于对话 ...

  9. Django: 之Web框架完美解析

    Web框架解析 Web通过Socket来监听客户端,,一旦发现客户发送的信息立刻接受.接受之后在服务端查找客户的请求,找到请求返回给用户,断开.这是一个连接,不断的接收,不断的返回. #!/usr/b ...

  10. JavaScript判断数组是否存在key

    JS中复合数组associative array和对象是等同的,判断一个key是否存在于数组中(或对象是否包含某个属性),不能使用ary[key] == undefined,因为可能存在ary = { ...