A:超级大水题;

代码:

 #include<cstdio>
#define maxn 105
using namespace std;
int n,a[maxn],x,y,ans;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&x);
a[i]=a[i-]+x;
ans+=x;
}
scanf("%d%d",&x,&y);
int i;
for(i=; i<=n; i++)
if(a[i]>=x&&a[i]<=y&&(ans-a[i])>=x&&(ans-a[i])<=y)
{
printf("%d",i+);
break;
}
if(i>n)printf("");
return ;
}

B:因为每次跳舞最多只有一个人以前跳过,所以很简单;

 #include<cstdio>
#define maxn 100005
using namespace std; int n,m,color[maxn],x,y,z; int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<m;i++)
{
scanf("%d%d%d",&x,&y,&z);
if(color[x]!=)
{
color[y]=(-color[x])/+;
color[z]=(-color[x]-color[y]);
}
else if(color[y]!=)
{
color[x]=(-color[y])/+;
color[z]=(-color[x]-color[y]);
}
else if(color[z]!=)
{
color[x]=(-color[z])/+;
color[y]=(-color[x]-color[z]);
}
else
{
color[x]=;
color[y]=;
color[z]=;
}
}
for(int i=;i<=n;i++)
printf("%d ",color[i]);
return ;
}

C:自己没出,学习了大神们的代码

用并查集来缩点太妙了!

 #include <cstdio>
using namespace std;
#define maxn 300100
int r[maxn],ret[maxn];
int find(int x)
{
if(x!=r[x])r[x]=find(r[x]);
return r[x];
}
int n,m,L,R,x;
int main()
{
scanf("%d%d",&n,&m);
for(int i=; i<=n+; i++)r[i]=i;
while(m--)
{
scanf("%d%d%d",&L,&R,&x);
int u;
u=find(L);
while()
{
if(u>=x)break;
ret[u]=x;
r[u]=u+;
u=find(u);
}
u=find(x+);
while()
{
if(u>R)break;
ret[u]=x;
r[u]=u+;
u=find(u);
}
}
for(int i=; i<=n; i++)
printf("%d ",ret[i]);
return ;
}

本题还可以用线段树来做,可惜当初学得太渣了!

花了一个下午学习线段树的延迟标记,终于会敲了!

线段树版代码:

 #include<cstdio>
#define maxn 300010
using namespace std; struct tree
{
int l,r,flag;
tree *left,*right;
} tr[maxn<<]; int m,n,ans,a[maxn],b[maxn],c[maxn],treecount; void build(tree *root,int l,int r)
{
root->l=l;
root->r=r;
root->flag=;
if(l==r)return;
int mid=(l+r)>>;
treecount++;
root->left=tr+treecount;
treecount++;
root->right=tr+treecount;
build(root->left,l,mid);
build(root->right,mid+,r);
} void insert(tree *root,int l,int r,int w)
{
if(l<=root->l&&r>=root->r)
{
root->flag=w;
return;
}
if(root->flag!=)
{
root->left->flag=root->right->flag=root->flag;
root->flag=;
}
int mid=(root->l+root->r)>>;
if(r<=mid)insert(root->left,l,r,w);
else if(l>=mid+)insert(root->right,l,r,w);
else
{
insert(root->left,l,mid,w);
insert(root->right,mid+,r,w);
}
} void query(tree *root,int x)
{
if(root->l==root->r){ans=root->flag;return;}
if(root->flag!=)
root->left->flag=root->right->flag=root->flag;
int mid=(root->l+root->r)>>;
if(x<=mid)query(root->left,x);
else query(root->right,x);
} int main()
{
scanf("%d%d",&n,&m);
build(tr,,n);
for(int i=; i<m; i++)
scanf("%d%d%d",&a[i],&b[i],&c[i]);
for(int i=m-; i>=; i--)
{
if(c[i]!=a[i])insert(tr,a[i],c[i]-,c[i]);
if(c[i]!=b[i])insert(tr,c[i]+,b[i],c[i]);
}
insert(tr,c[m-],c[m-],);
for(int i=; i<=n; i++)
{
query(tr,i);
printf("%d ",ans);
}
return ;
}

D:

假设la是第一个字符串的长度,lb是第二个的长度;

如果求出他们的最小公倍数 l 长度的串的哈密顿距离就行了;

但是不能直接求;

方法:找到任一一串中每个字符所对应的另外一个字符串中所出现的字符;

然后统计起来,乘上相应的倍数就行了!

代码:

 #define maxn 1000005
#define ll long long
#include<cstring>
#include<iostream>
using namespace std; char a[maxn],b[maxn];
ll cnt[maxn][];
ll gcd(ll x,ll y)
{
return (x%y)?gcd(y,x%y):y;
}
int main()
{
ll n,m,la,lb,g,l,ans;
cin>>n>>m;
cin>>a>>b;
la=strlen(a),lb=strlen(b);
g=gcd(la,lb);
l=la/g*lb;
ans=l;
for(ll i=;i<lb;i++)
cnt[i%g][b[i]-'a']++;
for(ll i=;i<la;i++)
ans-=cnt[i%g][a[i]-'a'];
cout<<ans*(n*la/l)<<endl;
return ;
}

E: 贪心

1.首先合并1和2,变成3;

2.如果1有剩,将1合并成3;如果合并完了之后还有剩:剩1,有3,+1;否则+2;

3.如果2有剩,将3个2合并成3,如果合并完之后还有剩,剩1个,有4,+1;否则+2;

代码:

 #include<iostream>
using namespace std;
int n,ans,a[],x,s;
int main()
{
cin>>n;
while(n--)
{
cin>>x;
a[x]++,s+=x;
}
if(s<||s==){cout<<"-1";return ;}
ans+=x=a[]<a[]?a[]:a[];
a[]-=x,a[]-=x,a[]+=x;
if(a[])
{
ans+=*(x=a[]/);
a[]-=x*;
a[]+=x;
if(a[])
{
if(a[]==&&a[])ans++;
else ans+=;
}
}
else
{
ans+=*(x=a[]/);
a[]-=x*;
a[]+=x*;
if(a[])
{
if(a[]==&&a[])ans++;
else ans+=;
}
}
cout<<ans;
}

Codeforces Round #207 (Div. 2)的更多相关文章

  1. Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)

    题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所 ...

  2. Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)

    脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...

  3. Codeforces Round #207 (Div. 2) A. Group of Students

    #include <iostream> #include <vector> using namespace std; int main(){ ; cin >> m ...

  4. Codeforces Round #207 (Div. 1)B(数学)

    数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include< ...

  5. Codeforces Round #207 (Div. 2)C

    读错题意了..线段树延迟标记 白刷这么多线段树 #include <iostream> #include<cstdio> #include<cstring> #in ...

  6. Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)

    题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...

  7. Codeforces Round #207 (Div. 1) D - Bags and Coins 构造 + bitset优化dp + 分段查找优化空间

    D - Bags and Coins 思路:我们可以这样构造,最大的那个肯定是作为以一个树根,所以我们只要找到一个序列a1 + a2 + a3 .... + ak 并且ak为 所有点中最大的那个,那么 ...

  8. Codeforces Round #207 (Div. 2)A B C E 水 思路 set 恶心分类

    A. Group of Students time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #207 (Div. 1) B (gcd的巧妙运用)

    比赛的时候不知道怎么写... 太弱了. 看了别人的代码,觉得这个是个经典的知识点吧. gcd的巧妙运用 自己想的时候苦苦思考怎么用dp求解. 无奈字符串太长而想不出好的算法. 其实在把a和b字符串都分 ...

随机推荐

  1. MFC 一个类訪问还有一个类成员对象的成员变量值

    作者:卿笃军 原文地址:http://blog.csdn.net/qingdujun/article/details/35263857 MFC中一个类要訪问另外一个类的的对象的成员变量值,这就须要获得 ...

  2. 3行3列表格 table实现,div+css实现

    table实现: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...

  3. JS获取图片上传地址

    function getObjectURL(file) { var url = null ; if (window.createObjectURL!=undefined) { // basic url ...

  4. CentOS7上Nginx的使用

    Nginx 的启动 指定配置文件的方式启动nginx # nginx -c /etc/nginx/nginx.conf 对于yum安装的nginx,使用systemctl命令启动 # systemct ...

  5. Visual Studio小技巧

    换了台电脑后打开解决方案后所有项目都是展开状态,每天工作的第一件事情就是把他们都折起来,感觉好麻烦. 百度了一阵子没找到相关的问题,还一度怀疑是不是我自己的VS有问题. 但是其它解决方案没有这种情况, ...

  6. TCP/IP 协议理解

    TCP/IP 协议(Transmission Control Protocol / internet Protocol),因特网互联协议,又名网络通讯协议.通俗而言:TCP负责发现传输的问题,一有问题 ...

  7. [Cookie] C#CookieHelper--C#操作Cookie的帮助类 (转载)

    点击下载 CookieHelper.rar 下面是代码大家看一下 /// <summary> /// 类说明:CookieHelper /// 联系方式:361983679 /// 更新网 ...

  8. SET NOCOUNT 的意义.

    SET NOCOUNT 使返回的结果中不包含有关受 Transact-SQL 语句影响的行数的信息. 语法 SET NOCOUNT { ON | OFF } 当 SET NOCOUNT 为 ON 时, ...

  9. JS事件监听 JS:attachEvent和addEventListener 使用方法

    attachEvent与addEventListener区别适应的浏览器版本不同,同时在使用的过程中要注意attachEvent方法          按钮onclickaddEventListene ...

  10. 在CentOS6.0上安装Oracle 11gR2 (11.2.0.1)以及基本的配置(一)

    首先安装CentOS6.0   就不用说了.安装即可.唯一需要注意的就是后面Oracle 11G Installation guide中的Checking the Software Requireme ...