codeforces 755D. PolandBall and Polygon
4 seconds
256 megabytes
standard input
standard output
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertexx + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
There are only two numbers in the input: n and k (5 ≤ n ≤ 106, 2 ≤ k ≤ n - 2, gcd(n, k) = 1).
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
5 2
2 3 5 8 11
10 3
2 3 4 6 9 12 16 21 26 31
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.






题目大意:一个n边形,从1号点开始,每次走到(x+k-1)%n+1位置,问每次留下来的路径把这个多边形划分成了几个部分。2 ≤ k ≤ n - 2, gcd(n, k) = 1,可以发现一定每个点一定经过一次,插入边的时候对应的点对应了一个区间,两条直线不相交(贡献答案)当且仅当他们的区间无交集,因为一个点只对应一个区间(只考虑出去的那个),用树状数组维护一下即可。
有个细节:如果2k>n,那么把k转化一下为n-k就可以了。(以为这个细节很显然,然后就没去hack,结果本来房间里10个对的然后就只剩3个没fst,MDZZ)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 1000010
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,cs[maxn],k,x,y,ans,c[maxn]; llg lowbit(llg x) {return x&-x;}
void add(llg w,llg v)
{
while (w<=n)
{
c[w]+=v; w+=lowbit(w);
}
}
llg sum(llg w)
{
llg ans=;
while (w>)
{
ans+=c[w]; w-=lowbit(w);
}
return ans;
} llg work(llg x,llg y)
{ llg l=y,r=y+n-k-k;
if (r>n)
{
r-=n;
return sum(n)-sum(l-)+sum(r);
}
else return sum(r)-sum(l-);
} int main()
{
yyj("D");
cin>>n>>k;
if (k>n/) k=n-k;
x=;
ans=;// add(1,1);
for (llg i=;i<=n;i++)
{
y=x+k;
if (y>n) y-=n;
ans+=i-work(x,y);
add(x,);
x=y;
printf("%lld ",ans);
}
return ;
}
codeforces 755D. PolandBall and Polygon的更多相关文章
- codeforces 755D. PolandBall and Polygon(线段树+思维)
题目链接:http://codeforces.com/contest/755/problem/D 题意:一个n边形,从1号点开始,每次走到x+k的位置如果x+k>n则到x+k-n的位置,问每次留 ...
- CodeForces 755D PolandBall and Polygon ——(xjbg)
每次连线,起点和终点之间,每一个被点亮的点,这些点都能连出去两条线,因此可以增加的块数+2(1这个点除外,因为只有连出的点没有连进的点),计算起点和终点之间有几个点被点亮即可,然后1这个点特判一下.感 ...
- cf 755D. PolandBall and Polygon
题意:把一个多边形往里面连对角线,然后问每次添加多边形被划分为几个部分 产生的部分就是新加对角线与原有对角线相交条数+1,用线段树(大雾)维护一下. #include<bits/stdc++.h ...
- 【codeforces 755D】PolandBall and Polygon
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces 755D:PolandBall and Polygon(思维+线段树)
http://codeforces.com/problemset/problem/755/D 题意:给出一个n正多边形,还有k,一开始从1出发,向第 1 + k 个点连一条边,然后以此类推,直到走完 ...
- 【树状数组】Codeforces Round #755 D. PolandBall and Polygon
http://codeforces.com/problemset/problem/755/D 每次新画一条对角线的时候,考虑其跨越了几条原有的对角线. 可以用树状数组区间修改点查询来维护多边形的顶点. ...
- D. PolandBall and Polygon BIT + 欧拉公式
http://codeforces.com/contest/755/problem/D // 我也觉得非平面图不能用欧拉公式,但是也能过,不知道为什么.求大佬留言. 这题其实就是平面图,因为它有很多个 ...
- codeforces 755C. PolandBall and Forest
C. PolandBall and Forest time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces 755F PolandBall and Gifts bitset + 二进制优化多重背包
PolandBall and Gifts 转换成置换群后, 对于最大值我们很好处理. 对于最小值, 只跟若干个圈能否刚好组能 k 有关. 最直观的想法就是bitset优化背包, 直接搞肯定T掉. 我们 ...
随机推荐
- Android编译,模块的编译和CLEAN
在Android源代码目录下的build目录下,有个脚本文件envsetup.sh: $ . build/envsetup.sh 注:该命令的前面的逗点(.),相当于source. 执行这个脚本文件后 ...
- ural1097 Square Country 2
Square Country 2 Time limit: 1.0 secondMemory limit: 64 MB The Square Parliament of the Square count ...
- ural1542 Autocompletion
Autocompletion Time limit: 2.0 secondMemory limit: 64 MB The Japanese are infinitely in love with ma ...
- 我的android学习脚步----------- 的第一个应用
刚刚开始学android开发,以前都是在别人调好的应用中修改JNI,现在需要自己一步步走 开发环境:Eclipse+ADT 配置不多讲了,引自:http://www.cnblogs.com/allen ...
- gridview中button事件处理
http://msdn.microsoft.com/zh-cn/library/bb907626.aspx 再结合如下: protected void GridView1_RowCommand(obj ...
- (转)java 排序算法
排序算法汇总(java实现,附源代码) 整理系统的时候发现了原来写的各种算法的总结,看了一下,大吃一惊,那时候的我还如此用心,具体的算法,有的已经模糊甚至忘记了,看的时候就把内容整理出来,顺便在熟 ...
- css hack总结
虽然说,现在讨论css hanck已经过时了,不过了解下还是好的. 各游览器常用兼容标记一览表: 标记 IE6 IE7 IE8 FF Opera Sarari [*+><] √ √ X X ...
- Struts2--Dynamic Result动态结果集
${r} : 表示配置文件xml可以读取action的valuestack的内容 1. jsp显示文件: <body> 动态结果 一定不要忘了为动态结果的保存值设置set get方法 &l ...
- 一个简单易懂的javascrip selection&range小案例
在制作富文本编辑器,尤其是在制作以div元素为编辑器区域时,当鼠标离开编辑区域以后会失去焦点,失去选区,这时候就要通过selection&range来重新设置选区.[以下代码尚未考虑IE低版本 ...
- Tomcat 静态部署 二步特别注意
一.修改server.xml 在Host 节点添加如下配置 <!-- path 为请求url地址 docBase 为项目文件绝对地址制定到WebContent根目录下 --> <Co ...