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 这组数 被黑的 ...
随机推荐
- cnn handwrite使用原生的TensorFlow进行预测
100个汉字,放在data目录下.直接将下述文件和data存在同一个目录下运行即可. 关键参数: run_mode = "train" 训练模型用,修改为validation 表示 ...
- 在新建FileInputStream时使用当前相对路径或者绝对路径作为参数的问题
今天在写一个关于配置Excel导出路径通过properties文件配置的需求,通过查询我得知 properties文件通过 FileInputStream 读取
- ab-如何提交post请求
ab -n 1 -c 1 -p post.txt http://***********/ 文件post.txt中存放要post的数据
- CF 809D Hitchhiking in the Baltic States——splay+dp
题目:http://codeforces.com/contest/809/problem/D 如果值是固定的,新加入一个值,可以让第一个值大于它的那个长度的值等于它. 如今值是一段区间,就对区间内的d ...
- 洛谷 1082 同余方程——exgcd(水题)
题目:https://www.luogu.org/problemnew/show/P1082 大水题. #include<iostream> #include<cstdio> ...
- centos7使用ceph-deploy部署ceph
准备阶段 准备yum源 删除默认的源,国外的比较慢 yum clean all rm -rf /etc/yum.repos.d/*.repo 下载阿里云的base源 wget -O /etc/yum. ...
- ++i和i++的效率孰优孰劣
在内建数据类型的情况下,效率没有区别: 在自定义数据类型的情况下,++i效率更高! 分析: (自定义数据类型的情况下) ++i返回对象的引用: i++总是要创建一个临时对象,在退出函数时还要销毁它,而 ...
- sizeToFit的学习与认知
今天一扫前两日的坏心情,终于有心情平静下来,今天我是根据网络上的一些资料进行学习,今天学习的内容是 sizeToFit() 方法在不方便手动布局的场景中的使用. 首先感谢资料的提供者:参考1 参考2 ...
- git常见错误及解决方案总结
git常见错误及解决方案总结 使用git在本地创建一个项目的过程 $ makdir ~/hello-world //创建一个项目hello- ...
- 【Data Structure & Algorithm】字符串全排列
字符串全排列 题目:输入一个字符串,打印出该字符串的所有排列.例如输入字符串abc,则输出由字符a.b.c所能排列出来的所有字符串abc.acb.bac.bca.cab.cba. 分析:考察对递归的理 ...