ural1521 War Games 2
War Games 2
Memory limit: 64 MB
Background
Problem
Input
Output
Sample
input | output |
---|---|
5 3 |
3 1 5 2 4 |
分析:约瑟夫出环顺序,树状数组;
每次出环是第几个是知道的,所以只需二分求出在原环上的标号即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,a[maxn],now;
void add(int x,int y)
{
for(int i=x;i<=n;i+=(i&(-i)))
a[i]+=y;
}
int get(int x)
{
int ans=;
for(int i=x;i;i-=(i&(-i)))
ans+=a[i];
return ans;
}
int main()
{
int i,j;
scanf("%d%d",&n,&k);
rep(i,,n)add(i,);
for(i=n;i>=;i--)
{
now=(now+k-)%i;
int l=,r=n,ans;
while(l<=r)
{
int mid=l+r>>;
if(get(mid)>=now+)ans=mid,r=mid-;
else l=mid+;
}
add(ans,-);
printf("%d ",ans);
}
//system("Pause");
return ;
}
ural1521 War Games 2的更多相关文章
- 战争游戏(War Games 1983)剧情
战争游戏 War Games(1983) 人工控制导弹发射 傍晚大雾,两值工作人员自驾一辆轿车到达监控俄罗斯核战争的防空基地,在门口出示工作证后进入基地,两工作人员和同事换班后,进入防空系统控制室开始 ...
- 1521. War Games 2(线段树解约瑟夫)
1521 根据区间和 来确定第k个数在哪 #include <iostream> #include<cstdio> #include<cstring> #inclu ...
- hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...
- ARTIFICIAL INTELLIGENCE FOR GAMES (Ian Millington / John Funge 著)
相关网站:http://www.ai4g.com PART I AI AND GAMESCHAPTER1 INTRODUCTIONCHAPTER2 GAME AIPART II TECHNIQUESC ...
- Google Code Jam 2014 资格赛:Problem D. Deceitful War
This problem is the hardest problem to understand in this round. If you are new to Code Jam, you sho ...
- Wind Simulation in 'God of War'(GDC2019 战神4风力场模拟)
Wind Simulation in 'God of War'(GDC2019) 战神4中的风力场模拟 这次带来的分享的主题是,圣莫妮卡工作室他们在战神4中关于GPU模拟风力场. 演讲者Rupert ...
- poj 1085 Triangle War (状压+记忆化搜索)
Triangle War Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2685 Accepted: 1061 Desc ...
- 用Maven部署war包到远程Tomcat服务器
过去我们发布一个Java Web程序通常的做法就是把它打成一个war包,然后用SSH这样的工具把它上传到服务器,并放到相应的目录里,让Tomcat自动去解包,完成部署. 很显然,这样做不够方便,且我们 ...
- 多War项目中静态文件的共享方案
[原创申明:文章为原创,欢迎非盈利性转载,但转载必须注明来源] 在互联网产品中,一般会有多个项目(Jar.WAR)组成一个产品线.这些WAR项目,因为使用相同的前端架构(jQuery.easyui等) ...
随机推荐
- how to add a shared lib in C?
http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html Basically, 2 steps: 1) make the ...
- 【我与一道水题的抗争之路】 哈理工2323 Emirp(反素数)
题目: http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2323 1,打表的姿势不对. ...
- qq客服问题
angularJs会给ng-href的不正常跳转,会 添加unsafe的前缀.原因是angular对href是有安全检查的,只能生成它认为安全的链接.解决方法如下: 在config.js中注入 fun ...
- 启动apache服务时报错【the requested operation has failed】
想要解决错误,首先要找到错误的原因. 使用ApacheMonitor.exe启动apache服务看不到任何错误的原因. 找到问题原因:cmd--命令端--切换到apache的bin目录,执行如下命令: ...
- mysql innobackupex备份工具
先简单介绍一下这个工具:innobackupexinnobackupex比xtarbackup有更强的功能,它整合了xtrabackup和其他的一些功能,他不但可以全量备份/恢复,还可以基于时间的增量 ...
- MyEclipse 2015 运行tomcat 内存溢出的解决方法
内存溢出错误: 2016-3-16 11:19:55 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() ...
- oracle登陆,在监听服务启动了的情况下,登陆用户还是报错未启动监听服务的错误(刚开始装oracle是能登陆的,重启之后装了plsql)
刚开始装oracle是能登陆的,重启之后装了140M的plsql,所以有可能是plsql跟oracle监听冲突了,所以我之后换了33M的plsql,oracle就没问题了,可以正常登陆了
- linux fork()函数
C语言编程创建函数fork() 执行解析 | 浏览:1842 | 更新:2013-04-22 15:12 | 标签:c语言 概述 最近在看进程间的通信,看到了fork()函数,虽然以前用过,这次经过思 ...
- WPF Template模版之DataTemplate与ControlTemplate【一】
WPF Template模版之DataTemplate与ControlTemplate[一] 标签: Wpf模版 2015-04-19 11:52 510人阅读 评论(0) 收藏 举报 分类: -- ...
- WPF 常用样式
TextBox <Window x:Class="WpfDemo.ListBoxTemaple" xmlns="http://schemas.microsoft.c ...