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下使用OpenCV 显示图像

    在Python3下用使用OpenCV比在C,C++里开发不止快捷一点点, 原型开发的时候蛮有用. 这里用的OpenCV 加载图片, 用的imshow画图 # -*- coding: utf-8 -*- ...

  2. Python学习笔记之面向对象编程(三)Python类的魔术方法

    python类中有一些方法前后都有两个下划线,这类函数统称为魔术方法.这些方法有特殊的用途,有的不需要我们自己定义,有的则通过一些简单的定义可以实现比较神奇的功能 我主要把它们分为三个部分,下文也是分 ...

  3. bzoj3505 / P3166 [CQOI2014]数三角形

    P3166 [CQOI2014]数三角形 前置知识:某两个点$(x_{1},,y_{1}),(x_{2},y_{2})\quad (x_{1}<x_{2},y_{1}<y_{2})$所连成 ...

  4. vijos 1096 津津的储存计划

    题目描述 Description 津津的零花钱一直都是自己管理.每个月的月初妈妈给津津300元钱,津津会预算这个月的花销,并且总能做到实际花销和预算的相同. 为了让津津学习如何储蓄,妈妈提出,津津可以 ...

  5. Tomcat下使用Log4j,按日期每天存放,解决catalina.out日志文件过大问题

    1. 准备jar包: log4j-1.2.17.jar (从 http://www.apache.org/dist/logging/log4j/1.2.17/ 下载) tomcat-juli.jar, ...

  6. xshell的Solarized Dark配色方案

    之前在ubuntu, kali, mint, air下都使用这一款配色方案,后来在网上看到有人在xshell中使用,配色方案有分享,就是一起无法导入 原来这个东西在你现有的连接无法直接导入,需要重新打 ...

  7. AP与CP介绍【转】

    本文转载子:https://blog.csdn.net/wqlinf/article/details/8663170 基带芯片加协处理器(CP,通常是多媒体加速器).这类产品以MTK方案为典型代表,M ...

  8. POJ 1751 Highways(最小生成树&Prim)题解

    思路: 一开始用Kruskal超时了,因为这是一个稠密图,边的数量最惨可能N^2,改用Prim. Prim是这样的,先选一个点(这里选1)作为集合A的起始元素,然后其他点为集合B的元素,我们要做的就是 ...

  9. BZOJ 5424: 烧桥计划

    BZOJ 5424: 烧桥计划 目前暂居rk1QAQ 首先,设\(f[i][k]\)为前i个点中,选了第i个点,总共选了k个点的答案.那么就有: \[f[i][k]=min_{j<i}\{f[j ...

  10. UVa 11054 Gergovia的酒交易

    https://vjudge.net/problem/UVA-11054 题意:直线上有n个等距的村庄,每个村庄要么买酒,要么卖酒.设第i个村庄对酒的需求为ai,ai>0表示买酒,ai<0 ...