Codeforces Round #250 (Div. 1)
这几次CF都挺惨。。
A
没条边权设为两端点的最小点权,最后加起来。
数组开小,WA一次
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 2010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int v[N];
int a[N];
int main()
{
int i,j,n,m;
cin>>n>>m;
for(i = ; i <= n; i++)
scanf("%d",&v[i]);
for(i = ; i <= m ;i++)
{
int x,y;
scanf("%d%d",&x,&y);
a[i] = min(v[x],v[y]);
}
int ans = ;
for(i = ;i <= m ;i++)
{
ans+=a[i];
}
cout<<ans<<endl;
return ;
}
B
以点权排序,删除某个点之后,哪些比它点权大的不再连通就说明那些点对的p值肯定为他的点权,想到了这点,却忘了并差集可以使不连通块连通。
做法:给每个边一个边权,为两端点的最小点权,以边权从大到小排序,依次进行合并,若当前不连通这以这个边权*块1的数量*块2的数量
排序的时候 错把m写成n wa一次。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int fa[N],res[N],a[N];
int find(int x)
{
if(fa[x]!=x)
{
fa[x] = find(fa[x]);
return fa[x];
}
return x;
}
struct node
{
int u,v,w;
}p[N];
bool cmp(node a,node b)
{
return a.w>b.w;
}
int main()
{
int n,m,i;
cin>>n>>m;
for(i = ; i <=n; i++)
{
scanf("%d",&a[i]);
fa[i] = i;
res[i] = ;
}
for(i = ;i <=m ;i++)
{
scanf("%d%d",&p[i].u,&p[i].v);
p[i].w = min(a[p[i].u],a[p[i].v]);
}
sort(p+,p+m+,cmp);
double ans = ;
for(i = ; i <= m ;i++)
{
int tx = find(p[i].u),ty = find(p[i].v);
if(tx!=ty)
{
fa[tx] = ty;
ans+=(double)p[i].w*res[tx]*res[ty];
res[ty]+=res[tx];
// res[tx] = 0;
}
}
printf("%.6f\n",(ans*)/(n*1.0*(n-)));
return ;
}
D
没有比这题更悲伤了,最后20分钟看,十几分钟敲完,最后十几秒交上,wa了,,发现少写了个lm。。。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100010
#define LL __int64
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
LL s[N<<],lm[N<<];
int a[N];
void up(int w)
{
s[w] = s[w<<]+s[w<<|];
lm[w] = max(lm[w<<],lm[w<<|]);
}
void build(int l,int r,int w)
{
if(l==r)
{
s[w] = a[l];
lm[w] = a[l];
return ;
}
int m = (l+r)>>;
build(l,m,w<<);
build(m+,r,w<<|);
up(w);
}
LL query(int a,int b,int l,int r,int w)
{
if(a<=l&&b>=r)
{
return s[w];
}
int m = (l+r)>>;
LL res=;
if(a<=m) res+=query(a,b,l,m,w<<);
if(b>m) res+=query(a,b,m+,r,w<<|);
return res;
}
void update(int p,int d,int l,int r,int w)
{
if(l==r)
{
s[w] = lm[w] = d;
return ;
}
int m = (l+r)>>;
if(p<=m) update(p,d,l,m,w<<);
else update(p,d,m+,r,w<<|);
up(w);
}
void find(int a,int b,int mod,int l,int r,int w)
{
if(a<=l&&b>=r)
{
if(lm[w] < mod)
return ;
if(l==r)
{
int k = s[w]%mod;
s[w] = lm[w] = k;
return ;
}
int m = (l+r)>>;
find(a,b,mod,l,m,w<<);
find(a,b,mod,m+,r,w<<|);
up(w);
return ;
}
int m = (l+r)>>;
if(a<=m) find(a,b,mod,l,m,w<<);
if(b>m) find(a,b,mod,m+,r,w<<|);
up(w);
}
int main()
{
int n,m,i;
cin>>n>>m;
for(i = ; i <=n; i++)
scanf("%d",&a[i]);
build(,n,);
int l,r,x,k;
while(m--)
{
scanf("%d",&k);
if(k==)
{
scanf("%d%d",&l,&r);
LL k = query(l,r,,n,);
printf("%I64d\n",k);
}
else if(k==)
{
scanf("%d%d%d",&l,&r,&x);
find(l,r,x,,n,);
}
else
{
scanf("%d%d",&k,&x);
update(k,x,,n,);
}
}
return ;
}
小小总结下:貌似每题都有注意不到的地方,还各不相同,说明不是我记忆力的问题,是注意力的问题,有空多刷几场TC,我印象中TC没有不出问题的时候,所以我现在依旧安稳的呆在DIV2。
发现学的多就会想得多,B题一直想在强连通分量上,心里觉得图的东西不是特别会,隐隐约约的觉得应该做不出来了,可又发现过的人好多,应该是会的,比赛的时候想的太多了,思路没有前行在正确的方向,注意力不能完全集中在题上。
Codeforces Round #250 (Div. 1)的更多相关文章
- Codeforces Round #250 (Div. 2)A(英语学习)
链接:http://codeforces.com/contest/437/problem/A A. The Child and Homework time limit per test 1 secon ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)
题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸
D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #250 (Div. 1) B. The Child and Zoo 并查集
B. The Child and Zoo Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...
- Codeforces Round #250 (Div. 1) A. The Child and Toy 水题
A. The Child and Toy Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...
- Codeforces Round #250 (Div. 2) A. The Child and Homework
注意题目长度不能考虑前缀,而且如果即存在一个选项的长度的两倍小于其他所有选项的长度,也存在一个选项的长度大于其他选项长度的两倍,则答案不是一个好的选择,只能选择C. #include <iost ...
- Codeforces Round #250 (Div. 2) C、The Child and Toy
注意此题,每一个部分都有一个能量值v[i],他移除第i部分所需的能量是v[f[1]]+v[f[2]]+...+v[f[k]],其中f[1],f[2],...,f[k]是与i直接相连(且还未被移除)的部 ...
- Codeforces Round #250 (Div. 2)
感觉不会再爱了,呜呜! A题原来HACK这么多!很多人跟我一样掉坑了! If there is some choice whose description at least twice shorter ...
- Codeforces Round #250 (Div. 2)——The Child and Set
题目链接 题意: 给定goal和limit,求1-limit中的若干个数,每一个数最多出现一次,且这些数的lowbit()值之和等于goal,假设存在这种一些数,输出个数和每一个数:否则-1 分析: ...
- Codeforces Round #250 (Div. 2)—A. The Child and Homework
好题啊,被HACK了.曾经做题都是人数越来越多.这次比赛 PASS人数 从2000直掉 1000人 被HACK 1000多人! ! ! ! 没见过的科技啊 1 2 4 8 这组数 被黑的 ...
随机推荐
- 并不对劲的bzoj1095:p2056:[ZJOI2007]捉迷藏
题目大意 给一\(n\)(\(n\leq10^5\))个点的一棵树,每个点有可能是黑色或白色,一开始所有点都是黑色,支持以下两种操作: 1.改变一个点的颜色 2.询问最远的黑色点对的距离 题解 据说是 ...
- jquery跨域3
这两天用 Jquery 跨域取数据的时候,经常碰到 invalid label 这个错误,十分的郁闷,老是取不到服务器端发送回来的 json 值, 一般跨域用到的两个方法为:$.ajax 和$.get ...
- javascript之创建对象的方式
1.object构造函数创建 var obj=new Object(); obj.name='xue'; 2.对象字面量创建 var obj={ name:'xue' } 3.构造函数创建 funct ...
- 微信小程序内嵌网页能力开放 小程序支持内嵌网页文档说明
为了方便开发者灵活配置微信小程序,张小龙现在开放了小程序的内嵌网页功能,这是一个非常大的惊喜啊,以后意味着你只要开放一个手机端网站,就可以制作一个小程序了哦.操作方法1.开发者登录微信小程序后台,选择 ...
- saltstack master minion安装配置简单使用
首先先了解下saltstack是什么,为什么使用它 它与Ansible.Puppet都属于集中管理工具,由于现在企业规模的不断庞大及业务的增长,所需要管理的服务器数量增多,而且大部分机器都属于同类业务 ...
- 使用memcpy 复制unsigned int 型的数据
转载请注明出处:http://blog.csdn.net/qq_26093511/article/details/53214692 函数原型: void *memcpy(void *dest, con ...
- bzoj4430
bit+容斥原理 我不会cdq分治只能用这个做法 考虑什么情况下不满足,至少有一个顺序不对就不行了,那么不满足的总有两对属性形成逆序对,那么我们用总方案数*2=n*(n-1)减去不符合的*2再/2就是 ...
- windows安装PHP5.4+Apache2.4+Mysql5.5
windows安装PHP5.4+Apache2.4+Mysql5.5 作者:星之宇 ┊ 时间:2012-10-18 14:27 ┊ 分类: 网站技术 ┊ 阅读:1232 ┊ 评论:16 最近听说PHP ...
- vs未能正确加载XX包的解决方法
管理员 -- cmd ---(进入到vs的安装目录下.如我的是:C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE)---d ...
- 2.5 Hive中外部表的讲解
一.外部表 1.hive中表的类型 管理表 托管表(外部表) #内部表 >内部表也称之为MANAGED_TABLE: >默认存储在/user/hive/warehouse下,也可以通过lo ...