Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
Alice and Bob are playing a game.
The game is played on a set of positive integers from 1 to n.
In one step, the player can choose a positive integer from the set, and erase all of its divisors from the set. If a divisor doesn't exist it will be ignored.
Alice and Bob choose in turn, the one who cannot choose (current set is empty) loses.
Alice goes first, she wanna know whether she can win. Please judge by outputing 'Yes' or 'No'.
 
Input
There might be multiple test cases, no more than 10. You need to read till the end of input.
For each test case, a line containing an integer n. (1≤n≤500)
 
Output
A line for each test case, 'Yes' or 'No'.
 
Sample Input
1
 
Sample Output
Yes
 
  如果先手取1可以获胜就取1,如果取1之后后手取y可以获胜,那么先手取y就好了,留下的局面是一样的,所以无论如何先手必胜。
  

 #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
while(cin>>n){
puts("Yes");
}
}

Naive Operations

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
In a galaxy far, far away, there are two integer sequence a and b of length n.
b is a static permutation of 1 to n. Initially a is filled with zeroes.
There are two kind of operations:
1. add l r: add one for al,al+1...ar
2. query l r: query ∑ri=l⌊ai/bi⌋
 
Input
There are multiple test cases, please read till the end of input file.
For each test case, in the first line, two integers n,q, representing the length of a,b and the number of queries.
In the second line, n integers separated by spaces, representing permutation b.
In the following q lines, each line is either in the form 'add l r' or 'query l r', representing an operation.
1≤n,q≤100000, 1≤l≤r≤n, there're no more than 5 test cases.
 
Output
Output the answer for each 'query', each one line.
 
Sample Input
5 12
1 5 2 4 3
add 1 4
query 1 4
add 2 5
query 2 5
add 3 5
query 1 5
add 2 4
query 1 4
add 2 5
query 2 5
add 2 2
query 1 5
 
Sample Output
1
1
2
4
4
6
 
  区间[l,r]全部加1,或者询问SUM{ floor(a[i]/b[i]) | l<=i<=r}
  注意到并不是所有情况下a[i]加上1之后都会使得a[i]/b[i]的结果发生变化,所以我们用minb[b]维护区间最小的b值,
query时如果当前区间的minb不为<=0就可以直接使用之前计算的值,否则就递归左右儿子将minb的值累加到sum中。
  其实就是个线段树乱搞,当时没想到,唉太菜了。
  

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN=;
int b[MAXN],n,m,l,r;
char s[];
class ST{
public:
#define lc (id<<1)
#define rc (id<<1|1)
#define mid ((L+R)>>1) int minb[MAXN<<],sum[MAXN<<],laz[MAXN<<]; void pushup(int id){
sum[id]=sum[lc]+sum[rc];
minb[id]=min(minb[lc],minb[rc]);
}
void pushdown(int id,int L,int R){
if(laz[id]){
laz[lc]+=laz[id],minb[lc]-=laz[id];
laz[rc]+=laz[id],minb[rc]-=laz[id];
laz[id]=;
}
}
void build(int id,int L,int R){
sum[id]=laz[id]=;
if(L==R){
scanf("%d",b+L);
minb[id]=b[L];
return;
}
build(lc,L,mid);
build(rc,mid+,R);
pushup(id);
}
void add(int id,int L,int R,int l,int r){ if(L>=l&&R<=r){
laz[id]++;
minb[id]--;
return ;
}
pushdown(id,L,R);
if(l<=mid) add(lc,L,mid,l,r);
if(r>mid) add(rc,mid+,R,l,r);
pushup(id);
}
int query(int id,int L,int R,int l,int r){
if(minb[id]>&&L>=l&&R<=r){
return sum[id];
}
if(L==R){
if(minb[id]<=){
int d=(-minb[id]+b[L])/b[L];
sum[id]+=d;
minb[id]=b[L]-(-minb[id]/*+b[L]-d*b[L]*/)%b[L];
}
return sum[id];
}
else{
pushdown(id,L,R);
int s=;
if(l<=mid) s+=query(lc,L,mid,l,r);
if(r>mid) s+=query(rc,mid+,R,l,r);
pushup(id);
return s;
}
}
}a;
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
a.build(,,n);
while(m--){
scanf("%s %d%d",s,&l,&r);
if(s[]=='a'){
a.add(,,n,l,r);
}
else{
printf("%d\n",a.query(,,n,l,r));
}
}
}
return ;
}

Swaps and Inversions

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
Long long ago, there was an integer sequence a.
Tonyfang think this sequence is messy, so he will count the number of inversions in this sequence. Because he is angry, you will have to pay x yuan for every inversion in the sequence.
You don't want to pay too much, so you can try to play some tricks before he sees this sequence. You can pay y yuan to swap any two adjacent elements.
What is the minimum amount of money you need to spend?
The definition of inversion in this problem is pair (i,j) which 1≤i<j≤n and ai>aj.
 
Input
There are multiple test cases, please read till the end of input file.
For each test, in the first line, three integers, n,x,y, n represents the length of the sequence.
In the second line, n integers separated by spaces, representing the orginal sequence a.
1≤n,x,y≤100000, numbers in the sequence are in [−109,109]. There're 10 test cases.
 
Output
For every test case, a single integer representing minimum money to pay.
 
Sample Input
3 233 666
1 2 3
3 1 666
3 2 1
 
Sample Output
0
3
 
  md,原来逆序对的数量就是使得数组变为有序的最少相邻元素交换次数,一开始并不知道这个原理,在纸上画了半天,最后写的时候发现了,哎这么弱智的东西搞了大半天。
  

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
int a[],b[];
LL C[],n;
map<int,int>M;
set<int>S;
set<int>::iterator it;
int lowbit(int x){
return x&-x;
}
int sum(int x){
LL ret=;
while(x>){
ret+=C[x];
x-=lowbit(x);
}
return ret;
}
void add(int x,int d){
while(x<=n){
C[x]+=d;
x+=lowbit(x);
}
}
int main(){
int x,y,i,j,k;
while(cin>>n>>x>>y){
memset(C,,sizeof(C));
M.clear();
S.clear();
LL ans=;
for(i=;i<=n;++i){
scanf("%d",a+i);
b[i]=a[i];
}
int tot=;
sort(b+,b++n);
for(i=;i<=n;++i){
if(M[b[i]]) continue;
M[b[i]]=++tot;
} for(i=n;i>=;--i){
ans+=sum(M[a[i]]-);
add(M[a[i]],);
}
cout<<ans*min(x,y)<<endl;
}
return ;
}

hdu多校(二) 1004 1007 1010的更多相关文章

  1. HDU 多校对抗赛第二场 1010 Swaps and Inversions

    Swaps and Inversions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. hdu多校第八场 1010(hdu6666) Quailty and CCPC 排序/签到

    题意: CCPC前10%能得金牌,给定队伍解题数和罚时,问你有没有一个队伍如果向上取整就金了,四舍五入就银了. 题解: 排序后按题意求解即可. #include<iostream> #in ...

  3. HDU 4699 Editor (2013多校10,1004题)

    Editor Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  4. HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)

    Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  5. HDU 4669 Mutiples on a circle (2013多校7 1004题)

    Mutiples on a circle Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Oth ...

  6. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  7. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  8. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

  9. 2015 HDU 多校联赛 5363 Key Set

    2015 HDU 多校联赛 5363 Key Set 题目: http://acm.hdu.edu.cn/showproblem.php? pid=5363 依据前面给出的样例,得出求解公式 fn = ...

随机推荐

  1. mysql删除有外链索引数据,Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法

    mysql删除有外链索引数据Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法查询:DELETE ...

  2. 谷歌笔试题--给定一个集合A=[0,1,3,8](该集合中的元素都是在0,9之间的数字,但未必全部包含), 指定任意一个正整数K,请用A中的元素组成一个大于K的最小正整数。

    谷歌笔试题--给定一个集合A=[0,1,3,8](该集合中的元素都是在0,9之间的数字,但未必全部包含), 指定任意一个正整数K,请用A中的元素组成一个大于K的最小正整数. Google2009华南地 ...

  3. Python入门之面向对象的__init__和__new__方法

    Python入门之面向对象的__init__和__new__方法

  4. 09: python基础补充

    1.1 闭包 1.闭包概念 1. 在一个外函数中定义了一个内函数,内函数里运用了外函数的临时变量,并且外函数的返回值是内函数的引用,这样就构成了一个闭包 2. 一般情况下,在我们认知当中,如果一个函数 ...

  5. CentOS7.3防火墙firewalld简单配置

    今天安装了centos7.3, 想用iptables的save功能保存规则的时候发现跟rhel不一样了,  后来度娘说centos用的是firewalld而不是iptables了, 平时工作都是用re ...

  6. bootstrap4

    lipsum, lorem生成假文, 是在编辑器中按tab键时生成的, 那个时候就已经生成了, 所以你在浏览器上看到的内容就是编辑器中的内容, 这个内容不会再变了. 所以你不要企图想刷新浏览器而改变假 ...

  7. HDU 4819 Mosaic (二维线段树&区间最值)题解

    思路: 二维线段树模板题,马克一下,以后当模板用 代码: #include<cstdio> #include<cmath> #include<cstring> #i ...

  8. 【Coursera】History: Dawn of Electronic Computing学后小结

    今天学习了Coursera上University of Michigan开的互联网的历史.技术和安全课程的FirstWeek内容. 先是吐槽下这个Coursera,认证非常麻烦,PC端需要摄像头拍照. ...

  9. SublimeText3常用快捷键和优秀插件(亲测)

    SublimeText3常用快捷键和优秀插件 SublimeText是前端的一个神器,以其精简和可DIY而让广大fans疯狂.好吧不吹了直入正题 -_-!! 首先是安装,如果你有什么软件管家的话搜一下 ...

  10. 【Python】【元编程】【从协议到抽象基类】

    """class Vector2d: typecode = 'd' def __init__(self,x,y): self.__x = float(x) self.__ ...