558C

题意:给你n个数,可对每一个数进行操作(乘2或者除以2)。求最少的操作使得全部的数都相等。

思路 : dp[ t ] 表示全部的数转化到 t 所需的最少操作, vis[ t ] 表示有多少数能够转化成 t 。

对于一个数 num , 把它所能到达的数用上述的数组记录下即可了(详细看代码)。

注意 :

输入:

3

5 4 4

输出 : 2  (5/2*2=4)

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=100010;
int n,vis[maxn],num[maxn];
void initial()
{
memset(num,0,sizeof(num));
memset(vis,0,sizeof(vis));
}
void deal(int op)
{
int tp=op,ct=0;
while(tp)
{
vis[tp]++;
num[tp]+=ct;
if(tp%2==1 && tp!=1)
{
int yp=tp/2*2,cnt=ct+2;
while(yp<maxn)
{
vis[yp]++;
num[yp]+=cnt;
yp*=2;
cnt++;
}
}
tp/=2;
ct++;
}
tp=op*2,ct=1;
while(tp<maxn)
{
vis[tp]++;
num[tp]+=ct;
tp*=2;
ct++;
}
}
void input()
{
int u;
for(int i=0;i<n;i++)
{
scanf("%d",&u);
deal(u);
}
}
void solve()
{
int Min=1<<30;
for(int i=0;i<maxn;i++) if(vis[i]==n) Min=min(Min,num[i]);
cout<<Min<<endl;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
initial();
input();
solve();
}
return 0;
}

558D

题意:给出n条信息。要你推断信息是否矛盾。或是否有多个出口,或是否有唯一出口。

信息有两种类型,一个是出口的若干区间,一个不是出口若干区间。

思路: 先通过出口的若干区间找出出口所在的树中根节点的区间。

然后在通过不是出

口的若干区间来推断。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std; struct node
{
ll l,r;
node(){}
node(ll _l,ll _r):l(_l),r(_r){}
};
vector <node> G;
int n,m;
ll st,ed;
bool cmp(node p,node q)
{
if(p.l==q.l) return p.r<q.r;
return p.l<q.l;
}
void initial()
{
G.clear();
st=(ll)1<<(n-1);
ed=((ll)1<<n)-1;
}
void input()
{
int tp,t;
ll u,v;
for(int i=0;i<m;i++)
{
scanf("%d %I64d %I64d %d",&tp,&u,&v,&t);
u=u<<(n-tp);
for(int j=0;j<n-tp;j++) v=v<<1|1;
if(t)
{
st=max(st,u);
ed=min(ed,v);
}
else G.push_back(node(u,v));
}
G.push_back(node(ed+1,ed+1));
}
void solve()
{
ll ans=-1;
sort(G.begin(),G.end(),cmp);
for(int i=0;i<G.size();i++)
{
if(st>ed) break;
if(st<G[i].l)
{
if(ans!=-1 || st+1<G[i].l)
{
cout<<"Data not sufficient!"<<endl;
return ;
}
ans=st;
}
st=max(st,G[i].r+1);
}
if(ans==-1) cout<<"Game cheated!"<<endl;
else cout<<ans<<endl;
}
int main()
{
while(scanf("%d %d",&n,&m)!=EOF)
{
initial();
input();
solve();
}
return 0;
}

558E

题意:给你一个长度为n的字符串(下标从1開始),然后给你m个操作。每一个操作有三个值 l,r,t。

假设t=1。表示将字符串中[ l ,r ]的部分依照升序排列。

假设t=0。表示将字符串中[
l ,r ]的部分依照降序排列。

最后要你输出原字符串经过m次操作后所形成的新的字符串。

思路:对于26个小写字母(a-z),分别建立线段树,即建26个线段树。

即每次改动 [ l , r ] 区间,则先通过26课线段树分别求出这个区间内的a–z的个数。然后将26课线

段树内的这一区间和置为0。

最后再依据顺序又一次给26课线段树的这一区间赋值即可了。

<span style="font-size:18px;">#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
const int N=100010;
const int M=26;
struct node
{
int l,r,sum,cover;
} a[M][N*4];
string str;
int n,m;
void build(int cnt,int l,int r,int k)
{
a[cnt][k].l=l;
a[cnt][k].r=r;
a[cnt][k].sum=0;
a[cnt][k].cover=-1;
if(l==r) return ;
int mid=(l+r)>>1;
build(cnt,l,mid,2*k);
build(cnt,mid+1,r,2*k+1);
}
void push_down(int cnt,int k)
{
if(a[cnt][k].cover!=-1)
{
a[cnt][k*2].cover=a[cnt][k*2+1].cover=a[cnt][k].cover;
a[cnt][k*2].sum=(a[cnt][k*2].r+1-a[cnt][k*2].l)*a[cnt][k*2].cover;
a[cnt][k*2+1].sum=(a[cnt][k*2+1].r+1-a[cnt][k*2+1].l)*a[cnt][k*2+1].cover;
a[cnt][k].cover=-1;
}
}
void update(int cnt,int l,int r,int k,int num)
{
if(l==a[cnt][k].l && r==a[cnt][k].r)
{
a[cnt][k].cover=num;
a[cnt][k].sum=(a[cnt][k].r+1-a[cnt][k].l)*num;
return ;
}
push_down(cnt,k);
int mid=(a[cnt][k].l+a[cnt][k].r)>>1;
if(r<=mid) update(cnt,l,r,2*k,num);
else if(l>mid) update(cnt,l,r,2*k+1,num);
else
{
update(cnt,l,mid,2*k,num);
update(cnt,mid+1,r,2*k+1,num);
}
a[cnt][k].sum=a[cnt][k*2].sum+a[cnt][k*2+1].sum;
}
int query(int cnt,int l,int r,int k)
{
if(l==a[cnt][k].l && r==a[cnt][k].r) return a[cnt][k].sum;
push_down(cnt,k);
int mid=(a[cnt][k].l+a[cnt][k].r)>>1;
if(r<=mid) return query(cnt,l,r,2*k);
else if(l>mid) return query(cnt,l,r,2*k+1);
else return query(cnt,l,mid,2*k)+query(cnt,mid+1,r,2*k+1);
}
void input()
{
for(int i=0; i<M; i++) build(i,1,n,1);
getchar();
getline(cin,str);
for(int i=1; i<=n; i++) update(str[i-1]-'a',i,i,1,1);
}
void solve()
{
int l,r,t;
while(m--)
{
int num[M];
scanf("%d %d %d",&l,&r,&t);
for(int i=0; i<M; i++)
{
num[i]=query(i,l,r,1);
update(i,l,r,1,0);
}
int pos=l;
if(t==1)
{
for(int i=0; i<M; i++)
if(num[i])
{
update(i,pos,pos+num[i]-1,1,1);
pos=pos+num[i];
}
}
else
{
for(int i=M-1; i>=0; i--)
if(num[i])
{
update(i,pos,pos+num[i]-1,1,1);
pos=pos+num[i];
}
}
}
for(int i=1; i<=n; i++)
for(int j=0; j<M; j++)
if(query(j,i,i,1))
{
printf("%c",j+'a');
break;
}
printf("\n");
}
int main()
{
while(scanf("%d %d",&n,&m)!=EOF)
{
input();
solve();
}
return 0;
}
</span>

Codeforces 558(C、D、E)总结的更多相关文章

  1. codeforces 558/C Amr and Chemistry(数论+位运算)

    题目链接:http://codeforces.com/problemset/problem/558/C 题意:把n个数变成相同所需要走的最小的步数易得到结论,两个奇数不同,一直×2不可能有重叠枚举每个 ...

  2. codeforces 558 E A Simple Task

    题目大意就是给一个字符串,然后多个操作.每次操作能够把每一段区间的字符进行升序或者降序排序,问终于的字符串是如何的. 做法的话就是用线段树维护区间和 一開始仅仅考虑字符串中字符'a'的情况.如果操作区 ...

  3. Codeforces Round #558 (Div. 2)

    目录 Codeforces Round #558 (Div. 2) 题解 A Eating Soup B Cat Party C Power Transmission D Mysterious Cod ...

  4. Codeforces Round #558 (Div. 2)-Cat Party (Hard Edition)-(前缀和 + 模拟)

    http://codeforces.com/problemset/problem/1163/B2 题意:有n天,每天有一个颜色,截取前x天,随便抽掉一天,使剩下的各个颜色出现的次数相等. 解题,也可以 ...

  5. Codeforces Round #558 (Div. 2)B(SET,模拟)

    #include<bits/stdc++.h>using namespace std;int a[100007];int cnt[100007];int main(){    int n; ...

  6. Codeforces Round #558 (Div. 2)C(计算几何,排列组合,模拟)

    #include<bits/stdc++.h>using namespace std;typedef struct{ double k,b;}node;node k[1000007];bo ...

  7. Codeforces Round 558(Div 2)题解

    这场比赛没有打,后来和同学们一起开了场镜像打…… B是SB题结果WA了5发…… C是SB题结果差5min调出……虽然中间有个老师讲题吃掉了1h D是比较神仙的题(2200),但是做出来了?算是比较超常 ...

  8. Codeforces Round #558 B2. Cat Party (Hard Edition)

    题面: 传送门 题目描述: 题意:确定最大的x,使去除掉前x天的其中一天后,所有不同数字的数量相等.   题目分析: 可能是我太久没打cf了,水题都做不出来. 这道题的关键在于:要记录相同数量,的不同 ...

  9. codeforces 558B. Amr and The Large Array 解题报告

    题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...

随机推荐

  1. CodeChef Counting on a directed graph

    Counting on a directed graph Problem Code: GRAPHCNT All submissions for this problem are available. ...

  2. C#获取二维数组的行数和列数及其多维。。。

    原文发布时间为:2008-11-26 -- 来源于本人的百度文章 [由搬家工具导入] 有一个二维数组sz[,] 怎样获取sz 的行数和列数呢? sz.GetLength(0) 返回第一维的长度(即行数 ...

  3. derby数据库的一些总结

     本文主要是针对在osgi开发过程中的一些问题进行总结,其中dbcp数据源的配置是在SpringDM下配置的.一,derby数据源的内嵌模式       该模式的主要应用是嵌入式程序,因为其小巧,且不 ...

  4. 二叉树遍历 Morris

    二叉树的遍历,先根遍历,不适用递归,存储空间为 O(1) 转自:http://chuansongme.com/n/100461 MorrisInOrder(): while 没有结束 如果当前节点没有 ...

  5. 洛谷——P2383 狗哥玩木棒

    P2383 狗哥玩木棒 题目背景 狗哥又趁着语文课干些无聊的事了... 题目描述 现给出一些木棒长度,那么狗哥能否用给出的木棒(木棒全用完)组成一个正方形呢? 输入输出格式 输入格式: 输入文件中的第 ...

  6. Android Spinner In Toolbar

    As the title of the post suggest in this tutorial we will see how to have spinner widget inside the ...

  7. MFC中 创建基于CFormView的文档视图程序

    在MFC中可以创建多种类型的窗口程序,如对话框程序.单文档结构程序(非文档/视图结构).单文档(文档/视图结构)以及多文档视图结构程序等. 在编写一般的小工具时,我们的首选显然是对话框程序,不过基于对 ...

  8. Kali Linux信息收集工具全

    可能大部分渗透测试者都想成为网络空间的007,而我个人的目标却是成为Q先生! 看过007系列电影的朋友,应该都还记得那个戏份不多但一直都在的Q先生(由于年级太长目前已经退休).他为007发明了众多神奇 ...

  9. 七天学会ASP.NET MVC (三)——ASP.Net MVC 数据处理 【转】

    http://www.cnblogs.com/powertoolsteam/p/MVC_three.html 第三天我们将学习Asp.Net中数据处理功能,了解数据访问层,EF,以及EF中常用的代码实 ...

  10. 2016.6.21 将Eclipse中项目部署到tomcat下

    新建的web项目,各种都配置好,选择run on server之后,发现运行失败,并不能访问需要的网址.而脱离eclipse,将生成的war文件直接放到tomcat的webapp下时,可以正常访问.所 ...