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 这组数 被黑的 ...
随机推荐
- keras中的Flatten和Reshape
最近在看SSD源码的时候,就一直不理解,在模型构建的时候如果使用Flatten或者是Merge层,那么整个数据的shape就发生了变化,那么还可以对应起来么(可能你不知道我在说什么)?后来不知怎么的, ...
- [LeetCode] Longest Valid Parentheses -- 挂动态规划羊头卖stack的狗肉
(Version 1.3) 这题在LeetCode上的标签比较有欺骗性,虽然标签写着有DP,但是实际上根本不需要使用动态规划,相反的,使用动态规划反而会在LeetCode OJ上面超时.这题正确的做法 ...
- 转C++的一点点
为什么突然放些这么水的东西?我还是个C++小萌新,XD [一 litTLE经验值] 1. 注意 C++里 自带pow(x,y) 使用是没问题,尤其是pow(x,0.333333)这种时候很有用.但是 ...
- 初学Java(一)
基本语法: 编写Java程序时,应注意以下几点: 1.大小写敏感:java是大小写敏感的,这就意味着标识符Hello与hello是不同的. 2.类名:对于所有的类来说,类名的首字母应该大写.如果类名由 ...
- android性能测试工具
Android性能测试工具Emmagee介绍 Emmagee介绍 Emmagee是监控指定被测应用在使用过程中占用机器的CPU.内存.流量资源的性能测试小工具.该工具的优势在于如同windows系 ...
- 推荐 BI Work
推荐阅读 BI Work 的文章,作为学习用 http://www.cnblogs.com/biwork
- Using MultiPath TCP to enhance home networks
Over the last few months I’ve been playing with MultiPath TCP and in this post I will show how I use ...
- 前端HTML 与css 整理(未完)
HTML 中的标签存放于文本文件中 需要按照以下固定的文档结构组织:<!DOCTYPE HTML><html> <head>头部相关信息 </head> ...
- c# 字符串大小写转换
//小转大 string lower = "converted from lowercase"; Console.WriteLine(lower.ToUpper()); //大转小 ...
- CodeForces754D【贪心】
题意: 有n个区间,每个区间覆盖区间里一段数,求最大连续区间长度被覆盖k次,并输出选取的区间. 思路: 贪心: 感觉一开始肯定是要把区间按left从小到大排序的. 然后肯定是连续k个区间能够达到的重叠 ...