Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)【A,B,C】
翻车!翻车!
codeforces782A
A题:
水。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int num[100010];
int main()
{
int n,x;
memset(num,0,sizeof(num));
scanf("%d",&n);
int sum=0,ans=0;
for(int i=1;i<=2*n;i++)
{
scanf("%d",&x);
if(!num[x])
{
num[x]++;
sum++;
}
else
{
sum--;
num[x]--;
}
ans=max(ans,sum);
}
printf("%d\n",ans);
return 0;
}
codeforces782B
B题:
三分,最短时间的位置位于最大位置和最小位置区间内,而时间是咋算的?所有点到位置的max,so两边扩散,肯定是越来越大,凹形曲线,三分求极值。
PS:注意精度1e-6.
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps=1e-6;
const int N=6e4+10;
struct asd{
double x,v;
}e[N];
int n;
bool cmp(asd a,asd b)
{
if(a.x<b.x) return true;
return false;
} double fun(double x)
{
double ans=0.0;
for(int i=1;i<=n;i++)
if(ans<(fabs(e[i].x-x)/e[i].v))
ans=(fabs(e[i].x-x)/e[i].v);
return ans;
} int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lf",&e[i].x);
for(int i=1;i<=n;i++)
scanf("%lf",&e[i].v);
sort(e+1,e+n+1,cmp);
double Left=e[1].x,Right=e[n].x;
double mid, midmid;
double mid_value, midmid_value;
while (Left +eps < Right)
{
mid = (Left + Right) / 2;
midmid = (mid + Right) / 2;
mid_value = fun(mid);
midmid_value = fun(midmid);
///求最大值改成>= 最小值改成<=
if (mid_value <= midmid_value) Right = midmid;
else Left = mid;
}
double ans=fun(Left);
printf("%.9lf\n",ans);
return 0;
}
codeforces782C
C题:
利用BFS可以轻松处理。
BFS是一层一层的,对于每个结点的儿子结点,都会有一些可以使用的颜色,except(他父亲的颜色,他父亲的父亲的颜色)。
外送两个案例:
7
1 2
3 2
2 4
4 5
5 6
5 7 7
1 2
2 3
2 4
2 5
5 6
5 7
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL; const int N=4e5+10; struct asd{
int to;
int next;
}e[N];
int head[N],tol;
bool vis[N];
int col[N],pre[N],in[N],t; void BFS(int pos)
{
queue<int>q;
memset(vis,0,sizeof(vis));
pre[0]=pre[pos]=0;
vis[pos]=true;
col[pos]=1;
t=1;
q.push(pos);
while(!q.empty())
{
int u=q.front();q.pop();
int tmp=t;
int num=t;
for(int i=head[u];~i;i=e[i].next)
{
int v=e[i].to;
if(vis[v]) continue;
q.push(v);
pre[v]=u;
vis[v]=true;
while(num&&(num==col[u]||num==col[pre[u]]))
num--;
if(num)
col[v]=num--;
else
col[v]=++tmp;
}
t=tmp;
}
}
void init()
{
tol=0;
memset(head,-1,sizeof(head));
memset(in,0,sizeof(in));
}
void add(int u,int v)
{
e[tol].to=v;
e[tol].next=head[u];
head[u]=tol++;
} int main()
{
int n,u,v;
scanf("%d",&n);
init();
for(int i=2;i<=n;i++)
{
scanf("%d%d",&u,&v);
add(u,v);
add(v,u);
in[u]++;
in[v]++;
}
int pos;
for(int i=1;i<=n;i++)
{
if(in[i]==1)
{
pos=i;
break;
}
}
BFS(pos);
int ans=0;
for(int i=1;i<=n;i++)
ans=max(ans,col[i]);
printf("%d\n",ans);
for(int i=1;i<=n;i++)
printf("%d ",col[i]);
return 0;
}
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)【A,B,C】的更多相关文章
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League
地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...
- 树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E
http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取 ...
- 2-sat Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D
http://codeforces.com/contest/782/problem/D 题意: 每个队有两种队名,问有没有满足以下两个条件的命名方法: ①任意两个队的名字不相同. ②若某个队 A 选用 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab
地址:http://codeforces.com/contest/782/problem/E 题目: E. Underground Lab time limit per test 1 second m ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons
地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed
地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A. Andryusha and Socks
地址:http://codeforces.com/contest/782/problem/A 题目: A. Andryusha and Socks time limit per test 2 seco ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A模拟 B三分 C dfs D map
A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- Redis3.x HA 方案(基于 Sentinel 方式)
第一部分 Redis-HA 搭建 一.Redis-HA 拓扑 一主两从,主从复制,故障时主从切换 三个Redis节点 + Sentinel 节点 Master 127.0.0.1 ...
- 关于SQL语句参数中为多个带‘,’的字符串
案例分析:画面为多分数选项,根据画面选择的分数组合=@分数,以SELECT * FROM [table_name] WHERE sore IN (@分数) 其实这不算一个复杂的问题,可能由于着急下班, ...
- 关于RabbitMQ简介
RabbitMQ是一个由erlang开发的AMQP(Advanced Message Queue )的开源实现.AMQP 的出现其实也是应了广大人民群众的需求,虽然在同步消息通讯的世界里有很多公开标准 ...
- PYTHON 爬虫笔记八:利用Requests+正则表达式爬取猫眼电影top100(实战项目一)
利用Requests+正则表达式爬取猫眼电影top100 目标站点分析 流程框架 爬虫实战 使用requests库获取top100首页: import requests def get_one_pag ...
- elasticsearch ——id字段说明,内部是_uid
_id field Each document indexed is associated with a _type (see the section called “Mapping Typesedi ...
- listen and translation exercise 53
It was hard work and there weren't any interesting things for him. You should be an expert with comp ...
- Linux下的磁盘缓存
转自:http://blog.csdn.net/cywosp/article/details/21126161 前段时间在开发一个使用SSD做缓存的系统,在高速写入数据时会出现大量的磁盘缓存.太多的磁 ...
- linux命令学习笔记-kill和killall命令详解
*杀死进程最安全的方法是单纯使用kill命令,不加修饰符,不带标志. 首先使用ps -ef命令确定要杀死进程的PID,然后输入以下命令: # kill -pid 注释:标准的kill命令通常都能达到目 ...
- ACM学习历程—ZOJ3878 Convert QWERTY to Dvorak(Hash && 模拟)
Description Edward, a poor copy typist, is a user of the Dvorak Layout. But now he has only a QWERTY ...
- Stamps
链接 分析:dp[i][j]表示前i个数,组成j,最少需要多少个.dp[i][j]=min(dp[i-1][j],dp[i-1][j-k*v[i]]+k),则可以转化为完全背包问题,同样的方法进行降维 ...