ural1521 War Games 2
War Games 2
Memory limit: 64 MB
Background
Problem
Input
Output
Sample
input | output |
---|---|
|
|
分析:约瑟夫出环顺序,树状数组;
每次出环是第几个是知道的,所以只需二分求出在原环上的标号即可;
代码:
- #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等) ...
随机推荐
- repeat a string in java
if I want to repeat "hello" four times as a new string-> "hellohellohellohello&quo ...
- 解决ORA-00904: invalid identifier标识符无效
方法/步骤 1 大部分情况下,此错误是由于引用了不存在的列名导致的.比如select name from Studtent 当studeng表中无name列时,系统就会报此错误. 2 解决思路是,确定 ...
- Ansible1:简介与基本安装【转】
Ansible是一个综合的强大的管理工具,他可以对多台主机安装操作系统,并为这些主机安装不同的应用程序,也可以通知指挥这些主机完成不同的任务.查看多台主机的各种信息的状态等,ansible都可以通过模 ...
- ASP.NET页面生命周期描述
下面是ASP.NET页面初始的过程:1. Page_Init();2. Load ViewState;3. Load Postback data;4. Page_Load();5. Handle co ...
- SQL Server 分页语句
表中主键必须为标识列,[ID] int IDENTITY (1,1) 1.分页方案一:(利用Not In和SELECT TOP分页) SELECT TOP 页大小 * FROM TestTable ...
- springMVC中ajax的运用于注意事项
ajax的运用: 注意事项: dataType:"json"在ajax中可写可不写(ajax能够自动识别返回值类型),写了更加规范,可以在ajax识别错误返回值类型的时候,指定返回 ...
- mysql 不能插入中文
三.#vim /etc/mysql/my.cnf .(5.5以前系统)在[client]下面加入 default-character-set=utf8 在[mysqld]下面加入default-cha ...
- 事件委托小demo(jq版)
<style type="text/css"> * { margin:; padding:; } .box1 { width: 200px; height: 60px; ...
- 解决centos无法上传文件和打开文件夹
使用yum搭建了ftp服务..yum的使用参考:http://blog.csdn.net/enson16855/article/details/9140623 windows使用FileZilla连接 ...
- 把vim变成C编辑器
转载一篇博客,地址是http://my.oschina.net/kutengshe/blog/423497