翻车!翻车!

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】的更多相关文章

  1. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  2. 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 ...

  3. 树的性质和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步,且这个步数是向上取 ...

  4. 2-sat Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D

    http://codeforces.com/contest/782/problem/D 题意: 每个队有两种队名,问有没有满足以下两个条件的命名方法: ①任意两个队的名字不相同. ②若某个队 A 选用 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 【学习笔记】快速傅里叶变换(FFT)

    [学习笔记]快速傅里叶变换 学习之前先看懂这个 浅谈范德蒙德(Vandermonde)方阵的逆矩阵的求法以及快速傅里叶变换(FFT)中IDFT的原理--gzy hhh开个玩笑. 讲一下\(FFT\) ...

  2. 使用了Tomcat JDBC连接池不能重连的问题

    在项目中用到了tomcat 的jdbc连接池,发现一个问题是,当数据库重启时,服务没有重新的去连接数据库,需要将部署的项目重新启动才能连接到数据库.经过测试对配置做一下修改: 在配置dataSourc ...

  3. linux中查看python的安装路径

    方法1:whereis python 查看所有python的路径,不止一个 方法2:which python 查看当前使用的python路径

  4. MVC+Ext.net零基础学习记录(四)

    在上一篇文章[MVC+Ext.net零基础学习记录(三)]中提到了利用MVC的Area可以做到项目分离,但是实际操作起来还是有很多问题的.比如,对于物理资源的访问,会报:没有相关资源 开始的时候,我在 ...

  5. Mysql远程登陆错误:ERROR 2003

    不能远程登陆Mysql,错误:ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.114' (10060).原因是电脑防火墙 ...

  6. JS 删除数组中指定的某个元素的方法

    //首先创建函数方法 Array.prototype.indexOf = function(val){ for(var i=0;i<this.length;i++){ if(this[i] == ...

  7. IoC~MVC3+EF+Autofac实现松耦合的系统架构

    MVC3+EF+Autofac网上这种文章确实没有,呵呵,今天就写一个,代大家分享! 这个系列的文章将带我们进入一种新的开发模式,注入开发模式,或者叫它IOC模式,说起IOC你可以这样去理解它,它为你 ...

  8. tomcat 6.0 安装及配置

    前提:安装并配置好jdk 1.免安装版存放目录:D:\01Install\tomcat

  9. 在线接口管理工具-eoapi

    为了方便和前端沟通,临时在局域网搭建了一个接口管理工具,查了一些资料都说eoapi不错,那就试了一下: 1.安装 要在服务器或者自己的电脑,准备web环境,Linux可以是Apache/nginx , ...

  10. ef 多个模块,通过程序集映射entity,指定对应的repository

    在Entity Framework repository下加两个方法: public virtual T GetByEntityName(object id, string EntityTypeNam ...