HDU 6188 Duizi and Shunzi

链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188

思路:

签到题,以前写的。

实现代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
const int MAX=1e5+;
int main()
{
int n,m,a[MAX],p,ans,k;
while(scanf("%d",&n)!=EOF)
{
ans=;
for(int i = ;i <= n;i ++)
a[i]=;
for(int i = ;i <= n;i ++)
cin>>p,a[p]++;
for(int i = ;i <= n;i ++)
{
if(a[i]>=)
{
ans+=a[i]/;
a[i]%=;
}
if(i<=n-&&a[i]&&a[i+]%&&a[i+])
a[i]--,a[i+]--,a[i+]--,ans+=;
}
cout<<ans<<endl;
}
}

HDU 6182  A Math Problem

链接:http://acm.hdu.edu.cn/showproblem.php?pid=6182

思路: 签到

实现代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll M = 1e18+;
ll a[];
int main()
{
ll k = ;
ll n,m;
for(ll i = ;i<=;i++){
ll ans = ;
for(ll j=;j<=i;j++){
ans*=i;
}
//cout<<ans<<endl;
if(ans<=M)
a[k++] = ans;
else
break;
}
while(scanf("%lld",&n)!=EOF){
if(n>)
cout<<<<endl;
else{
for(ll i=;i<k;i++){
if(a[i]>n){
cout<<i<<endl;break;
}
else if(a[i]==n){
cout<<i+<<endl;break;
}
}
}
}
return ;
}

HDU 6186 CS Course

链接: http://acm.hdu.edu.cn/showproblem.php?pid=6186

思路:签到题

实现代码:

#include<bits/stdc++.h>
using namespace std;
const int M = ;
#define ll long long
ll a[M],or1[M],or2[M],and2[M],and1[M],xor1[M],xor2[M];
int main()
{
ll n,q,i,x;
while(scanf("%lld%lld",&n,&q)!=EOF){
for(i=;i<=n;i++){
scanf("%lld",&a[i]);
}
or1[] = a[];and1[] = a[]; xor1[] = a[];
for(i=;i<=n;i++){
or1[i] = (or1[i-]|a[i]);
and1[i] = (a[i]&and1[i-]);
xor1[i] = (xor1[i-]^a[i]);
}
or2[n] = a[n]; and2[n] = a[n];xor2[n] = a[n];
for(i=n-;i>=;i--){
or2[i] = (a[i]|or2[i+]);
and2[i] = (a[i]&and2[i+]);
xor2[i] = (a[i]^xor2[i+]);
}
//cout<<and1[2]<<" "<<(a[1]&a[2])<<endl;
ll y;
for(i=;i<q;i++){
scanf("%lld",&y);
if(y==)
printf("%lld %lld %lld\n",and2[],or2[],xor2[]);
else{
if(y==n)
printf("%lld %lld %lld\n",and1[n-],or1[n-],xor1[n-]);
else
printf("%lld %lld %lld\n",(and1[y-]&and2[y+]),(or1[y-]|or2[y+]),(xor1[y-]^xor2[y+]));
}
}
}
return ;
}

HDU 6183 Color it

链接: http://acm.hdu.edu.cn/showproblem.php?pid=6183

思路:线段树+动态开点

有50种颜色,对每一种颜色建一颗线段树维护,动态开点。
第一种操作:使点(x,y)的颜色变为c
第二种:询问(1,y1),(x,y2)两点间的颜色种类数量
我们可以以y轴建线段树,横坐标为值,那么要确定两点之前是否存在某种颜色,只要询问下每个颜色在y1,y2之间最小的值(也就是横坐标).判断下最小值是否小于第二种操作给出的x,如果小于的话就代表两点间存在这种颜色。 突然发现这道题以前也写过。。。。 实现代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mid int m = (l + r) >> 1
const int M = 1e6+;
int n = 1e6,flag=;
int sum[M],ne=,ls[M],rs[M],rt[]; void update(int &k,int l,int r,int p,int num){
if(!k){ //如果当前区间未拓展,拓展并赋值
k = ++ne;
sum[k] = num;
}
sum[k] = min(sum[k],num);//当前区间有值,更新下最小值
if(l == r)
return ;
mid;
if(p <= m) update(ls[k],l,m,p,num);
else update(rs[k],m+,r,p,num);
} void query(int k,int L,int R,int l,int r,int up){
if(!k||flag) return ;
if(L <= l&&R >= r){
if(sum[k]<=up)
flag = ;
return;
}
mid;
if(L <= m) query(ls[k],L,R,l,m,up);
if(R > m) query(rs[k],L,R,m+,r,up);
return ;
} void init(){
memset(rt,,sizeof(rt));
memset(sum,,sizeof(sum));
memset(ls,,sizeof(ls));
memset(rs,,sizeof(rs));
ne = ;
}
int main()
{
int op,x,y,z;
while(~scanf("%d",&op)){
if(op == )
init();
else if(op == ){
scanf("%d%d%d",&x,&y,&z);
update(rt[z],,n,y,x);
}
else if(op == ){
scanf("%d%d%d",&x,&y,&z);
int ans = ;
for(int i = ;i <= ;i ++){
flag = ;
query(rt[i],y,z,,n,x);
if(flag) ans++;
}
printf("%d\n",ans);
}
else return ;
}
return ;
}

HDU 6191 Query on A Tree

链接: http://acm.hdu.edu.cn/showproblem.php?pid=6191

思路:dfs序 + 可持久化Trie树

用dfs序把树转换成序列,由于dfs序的特性,子树在序列中是连续的一段区间,那么对这段区间我们可以用可持久化trie来查询与x异或最大的值。

实现代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1e5+;
int a[M];
int rt[M],tot,tree[M<<][],son[M<<][],idx,in[M],out[M],cnt,head[M];
vector<int>g[M];
template <class T>
void read(T &x){
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x){
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
} void Insert(int old,int now,int x,int pos){
if(pos < ) return;
int tmp = (x&(<<pos))>;
tree[now][tmp] = tree[old][tmp] + ;
tree[now][tmp^] = tree[old][tmp^];
son[now][tmp^] = son[old][tmp^];
Insert(son[old][tmp],son[now][tmp]=++idx,x,pos-);
} void dfs(int u){
in[u] = ++tot;
Insert(rt[in[u]-],rt[in[u]]=++idx,a[u],);
for(int i = ;i < g[u].size();i ++){
dfs(g[u][i]);
}
out[u] = tot;
} int query(int old,int now,int x,int ans,int pos){
if(pos < ) return ans;
int tmp=!!(x&(<<pos));
if(tree[now][tmp^]>tree[old][tmp^])
return query(son[old][tmp^],son[now][tmp^],x,ans|(<<pos),pos-);
else
return query(son[old][tmp],son[now][tmp],x,ans,pos-);
}
int init(){
memset(rt,,sizeof(rt));
memset(son,,sizeof(son));
memset(tree,,sizeof(tree));
idx = ,tot = ;
}
int main(){
int n,q,x,z,y;
while(scanf("%d%d",&n,&q)!=EOF){
init();
for(int i = ;i <= n;i ++){
read(a[i]);
}
for(int i = ;i <= n;i ++){
read(z);
g[z].push_back(i);
}
dfs();
while(q--){
read(x),read(y);
write(query(rt[in[x]-],rt[out[x]],y,,));
putchar('\n');
}
for(int i = ;i <= n;i ++)
g[i].clear();
}
return ;
}

2017ACM/ICPC广西邀请赛-重现赛的更多相关文章

  1. 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi

    Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...

  2. 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree

    Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...

  3. 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering

    Problem Description Bob's school has a big playground, boys and girls always play games here after s ...

  4. 2017ACM/ICPC广西邀请赛-重现赛 1001 A Math Problem

    2017-08-31 16:48:00 writer:pprp 这个题比较容易,我用的是快速幂 写了一次就过了 题目如下: A Math Problem Time Limit: 2000/1000 M ...

  5. 2017ACM/ICPC广西邀请赛-重现赛1005 CS course

    2017-08-31 16:19:30 writer:pprp 这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前 的训练都是面向题解编程的缘故吧,以后不能这样了,另 ...

  6. 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)

    上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/3 ...

  7. HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序

    题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...

  8. 2017ACM/ICPC广西邀请赛

    A.A Math Problem #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll ...

  9. 2017ACM/ICPC广西邀请赛 Duizi and Shunzi

    题意:就是一个集合分开,有两种区分 对子:两个相同数字,顺子:连续三个不同数字,问最多分多少个 解法:贪心,如果当前数字不构成顺子就取对子 /2,如果可以取顺子,那么先取顺子再取对子 #include ...

随机推荐

  1. sql实时提交事务

    public void deleteByHbtlidAndDept(String class_id,String depart_id) { Session session = this.getHibe ...

  2. Codeforces round 1098

    Div1 530 感受到被Div1支配的恐惧了.jpg 真·一个题都不会.jpg(虽然T1是我智障 感受到被构造题支配的恐惧了.jpg A 直接树上贪心就行,是我写错了.jpg B 这个构造超级神仙有 ...

  3. angularjs为ng-click事件传递参数

    在angularjs开发中,我们需要为ng-click事件传递一个参数. 在js中,可以接到参数: 演示:

  4. RNN介绍,较易懂

    人类并不是每时每刻都从一片空白的大脑开始他们的思考.在你阅读这篇文章时候,你都是基于自己已经拥有的对先前所见词的理解来推断当前词的真实含义.我们不会将所有的东西都全部丢弃,然后用空白的大脑进行思考.我 ...

  5. Spring+SpringMVC+MyBatis+easyUI整合进阶篇(十二)Spring集成Redis缓存

    作者:13 GitHub:https://github.com/ZHENFENG13 版权声明:本文为原创文章,未经允许不得转载. 整合Redis 本来以为类似的Redis教程和整合代码应该会很多,因 ...

  6. cf946d 怎样逃最多的课dp

    来源:codeforces                                              D. Timetable Ivan is a student at Berland ...

  7. Map获取key值

    有两种方法 public static void test4(){ Map<String, Object> map = new HashMap<>(); map.put(&qu ...

  8. 访谈:BugPhobia’s Brief Communication

    0x01 :采访的学长简介 If you weeped for the missing sunset, you would miss all the shining stars 梁野,北京航空航天大学 ...

  9. linux内核分析第七次实验

    实验: rm menu -rf git clone https://github.com/megnning/menu.git cd menu ls mv test_exec.c test.c vi t ...

  10. 5.2&5.3

    队友吕日荣 http://www.cnblogs.com/Russelling/ 最近队友有点忙,尽管如此,队友还是有很给力的付出,让我们在最后完成了任务. 一开始都不知道这次的任务是要做什么,毫无头 ...