Codeforces Round #207 (Div. 2)
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)的更多相关文章
- 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所 ...
- Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)
脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...
- Codeforces Round #207 (Div. 2) A. Group of Students
#include <iostream> #include <vector> using namespace std; int main(){ ; cin >> m ...
- Codeforces Round #207 (Div. 1)B(数学)
数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include< ...
- Codeforces Round #207 (Div. 2)C
读错题意了..线段树延迟标记 白刷这么多线段树 #include <iostream> #include<cstdio> #include<cstring> #in ...
- Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)
题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...
- Codeforces Round #207 (Div. 1) D - Bags and Coins 构造 + bitset优化dp + 分段查找优化空间
D - Bags and Coins 思路:我们可以这样构造,最大的那个肯定是作为以一个树根,所以我们只要找到一个序列a1 + a2 + a3 .... + ak 并且ak为 所有点中最大的那个,那么 ...
- 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 ...
- Codeforces Round #207 (Div. 1) B (gcd的巧妙运用)
比赛的时候不知道怎么写... 太弱了. 看了别人的代码,觉得这个是个经典的知识点吧. gcd的巧妙运用 自己想的时候苦苦思考怎么用dp求解. 无奈字符串太长而想不出好的算法. 其实在把a和b字符串都分 ...
随机推荐
- LRU算法&&LeetCode解题报告
题目 Design and implement a data structure for Least Recently Used (LRU) cache. It should support the ...
- PCAP 抓包
PCAP是一个数据包抓取库, 很多软件都是用它来作为数据包抓取工具的. WireShark也是用PCAP库来抓取数据包的.PCAP抓取出来的数据包并不是原始的网络字节流,而是对其进行从新组装,形成一种 ...
- Android自定义DataTimePicker(日期选择器)
实现的效果就是在同一个布局上显示日期选择和时间选择,时间不准确bug修复 1.自定义类DateTimePickDialogUtil.java public class DateTimePickDial ...
- Android开发之意图解析
android中意图(intent)就是告诉系统要做某件事情.比如要拨打电话或者发送短信. 或者在一个Activity中点击按钮跳转到另外一个activity时也用到意图.意图分为两种:显示意图和隐 ...
- windows向ubuntu过渡之常用编程软件安装
不出意外的上篇文章又被踢出首页了,心情甚是悲桑..希望更多人能看到 1.安装codeblocks 直接在软件中心搜索codeblocks就可以 2.安装jdk并配置环境变量 http://www.li ...
- python sklearn.linear_model.LinearRegression.score
score(self, X, y, sample_weight=None) 作用:返回该次预测的系数R2 其中R2 =(1-u/v).u=((y_true - y_pred) ** 2).su ...
- 用Module元素实现SharePoint Webpart Page的自动生成
最近研发的项目中开发了很多的WebPart,每次部署这些WebPart到新环境中总是很麻烦,因为自己要新创建WebpartPage,同时还要把这些WebPart放到指定的WebPart页中去: 为了方 ...
- css3 盒模型
0,前言 在css2.1 之前,我们都熟知的两种盒模型,一种是w3c标准盒模型,另外一种是怪异模式下的盒模型.在css3之前我们一直使用的是标准盒模型,但是标准盒模型的宽度总是需要小心的去使用,稍有不 ...
- PHP的无限栏目分类
自己在PHP的无线栏目分类上面就是搞了很久都没有明白,所以现在是趁着记忆力还没有完全的消退的时候速度的记录下来 这里讲解的是最简单的树形栏目,适合的是小中型的栏目分类需求 1.这里讲解的是针对是只要通 ...
- SQL语句一之建库
USE master --转到系统表goIF EXISTS(SELECT * FROM sysdatabases WHERE name ='Test') --查询是否存在Test数据库DROP DA ...