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. python3.4学习笔记(二十二) python 在字符串里面插入指定分割符,将list中的字符转为数字

    python3.4学习笔记(二十二) python 在字符串里面插入指定分割符,将list中的字符转为数字在字符串里面插入指定分割符的方法,先把字符串变成list然后用join方法变成字符串str=' ...

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

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

  3. P3498 [POI2010]KOR-Beads

    P3498 [POI2010]KOR-Beads 题解 hash+hash表+调和级数 关于调和级数(from baidu百科): 调和级数发散的速度非常缓慢.举例来说,调和序列前10项的和还不足10 ...

  4. C# MVC框架初学者

    推荐网站:http://blog.csdn.net/zhuyu19911016520/article/category/6318590

  5. Python3基础 os chdir 改变工作目录

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. PyCharm/IDEA 使用技巧总结

    基本概念 IDEA 没有类似 Eclipse 的工作空间的概念(workspace),最大单元就是 Project.这里可以把 Project 理解为 Eclipse 中的 workspace.Mod ...

  7. BZOJ 1044: [HAOI2008]木棍分割 DP 前缀和优化

    题目链接 咳咳咳,第一次没大看题解做DP 以前的我应该是这样的 哇咔咔,这tm咋做,不管了,先看个题解,再写代码 终于看懂了,卧槽咋写啊,算了还是抄吧 第一问类似于noip的那个跳房子,随便做 这里重 ...

  8. [BZOJ1103][POI2007]大都市meg dfs序+树状数组

    Description 在经济全球化浪潮的影响下,习惯于漫步在清晨的乡间小路的邮递员Blue Mary也开始骑着摩托车传递邮件了.不过,她经常回忆起以前在乡间漫步的情景.昔日,乡下有依次编号为1..n ...

  9. React Native API之 ActionSheetIOS

    ok!先来演示是下效果: 官网教程:http://reactnative.cn/docs/0.31/actionsheetios.html#content 上代码:引入API组件: import Re ...

  10. Axure RP 8.0 Licence

    新版本:(比如 Axure RP 8.0.0 3319)Licensee:米 业成 (STUDENT)Key:nFmqBBvEqdvbiUjy8NZiyWiRSg3yO+PtZ8c9wdwxWse4W ...