Link:

Codeforces #514 传送门

很简单的一场比赛打崩了也是菜得令人无话可说……

D:

一眼二分,发现对于固定的半径和点,能包含该点的圆的圆心一定在一个区间内,求出区间判断即可

此题一个重要性质就是圆与$x$轴相切,画出圆心所在直线后就能想到上述贪心了

#include <bits/stdc++.h>

using namespace std;
#define X first
#define Y second
#define pb push_back
typedef double db;
typedef long long ll;
typedef pair<db,db> P;
const db eps=1e-;
const int MAXN=1e5+;
struct Data{db l,r;int id;}a[MAXN];
int n,cnt1,cnt2;P dat[MAXN]; bool cmp(Data a,Data b)
{return a.l<b.l;}
db sqr(db x){return 1.0*x*x;}
bool cal(db r,int k)
{
db b=*dat[k].X;
db c=sqr(dat[k].X)+sqr(dat[k].Y-r)-sqr(r);
if(sqr(b)-*c<-eps) return false;
a[k].id=k;
a[k].l=(b-sqrt(sqr(b)-*c))/2.0;
a[k].r=(b+sqrt(sqr(b)-*c))/2.0;
return true;
}
bool check(db r)
{
if(cnt1) r=-r;
for(int i=;i<=n;i++)
if(!cal(r,i)) return false;
db mn=1e60,mx=-1e60;
for(int i=;i<=n;i++)
mn=min(mn,a[i].r),mx=max(mx,a[i].l);
return mx<=mn;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&dat[i].X,&dat[i].Y);
cnt1+=dat[i].Y<;cnt2+=dat[i].Y>;
}
if(n==) return printf("%.6lf",dat[].Y/2.0),;
if(cnt1&&cnt2) return puts("-1"),; //实数二分最好直接枚举次数,否则精度可能不够
// 也可以相对误差和eps比较
db l=,r=1e16;
for(int i=;i<=;i++)
{
db mid=(l+r)/2.0;
if(check(mid)) r=mid;
else l=mid;
}
printf("%.6lf",l);
return ;
}

Problem D

做的时候先想的凸包,想到正解后把一个$int$开成$double$后调不出来……

所以发现输出全是整数时要敏感啊……

注意:实数二分不用$fabs(l-r)$,会爆精度,最好卡次数

E:

可以先预处理每个点向上走的最远距离在树上$dp$,

不过其实直接从低向上贪心走就好了,在之前被走过的点就不用走了

可以并查集维护也可以直接暴力走

#include <bits/stdc++.h>

using namespace std;
#define X first
#define Y second
#define pb push_back
typedef double db;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=2e5+;
ll S,w[MAXN],pre[MAXN],res;
int n,L,f[MAXN],ufs[MAXN],vis[MAXN],dep[MAXN],out[MAXN]; int find(int x)
{return x==ufs[x]?x:find(ufs[x]);}
int main()
{
scanf("%d%d%lld",&n,&L,&S);
for(int i=;i<=n;i++) scanf("%lld",&w[i]);
for(int i=;i<=n;i++)
scanf("%d",&f[i]),out[f[i]]++;
for(int i=;i<=n;i++)
{
ufs[i]=i;
if(w[i]>S) return puts("-1"),;
}
for(int i=;i<=n;i++)
dep[i]=dep[f[i]]+,pre[i]=pre[f[i]]+w[i]; queue<int> q;
for(int i=;i<=n;i++)
if(!out[i]) q.push(i);
while(!q.empty())
{
int t=q.front();q.pop();
if(vis[t]) continue;
int cur=t;res++;
int len=;ll sum=;
while(len<=L&&sum<=S)
{
int nxt=find(cur);
len+=dep[cur]-dep[nxt]+;
sum+=pre[cur]-pre[nxt]+w[nxt];
if(len>L||sum>S) break;
vis[nxt]=;if(!f[nxt]) break; ufs[nxt]=find(f[nxt]);out[f[nxt]]--;
if(!out[f[nxt]]&&!vis[f[nxt]]) q.push(f[nxt]);
cur=f[nxt];
}
}
printf("%lld",res);
return ;
}

Problem E

以后做完签到题后把所有题先看一遍再决定顺序!

[Codeforces #514] Tutorial的更多相关文章

  1. Codeforces 514 D R2D2 and Droid Army(Trie树)

    题目链接 大意是判断所给字符串组中是否存在与查询串仅一字符之差的字符串. 关于字符串查询的题,可以用字典树(Trie树)来解,第一次接触,做个小记.在查询时按题目要求进行查询. 代码: #define ...

  2. codeforces#514 Div2---1059ABCD

    1059A---Cashier http://codeforces.com/contest/1059/problem/A 题意: Vasya每天工作\(l\)个小时,每天服务\(n\)个顾客,每个休息 ...

  3. [Codeforces #172] Tutorial

    Link: Codeforces #172 传送门 A: 一眼看上去分两类就可以了 1.每个矩形只有两条边相交,重合的形状为菱形 2.每个矩形四条边都有相交 对于情况1答案为$h*h/sin(a)$ ...

  4. [Codeforces #210] Tutorial

    Link: Codeforces #210 传送门 A: 贪心,对每个值都取最大值,不会有其他解使答案变优 #include <bits/stdc++.h> using namespace ...

  5. [Codeforces #196] Tutorial

    Link: Codeforces #196 传送门 A: 枚举 #include <bits/stdc++.h> using namespace std; #define X first ...

  6. [Codeforces #174] Tutorial

    Link: Codeforces #174 传送门 A: 求原根的个数,有一条性质是原根个数为$\phi(\phi(n))$,多了一个不会证的性质 如果要确定哪些是原根的话还是要枚举,不过对于每个数不 ...

  7. [Codeforces #190] Tutorial

    Link: Codeforces #190 传送门 A: 明显答案为$n+m-1$且能构造出来 #include <bits/stdc++.h> using namespace std; ...

  8. [Codeforces #211] Tutorial

    Link: Codeforces #211 传送门 一套非常简单的题目,但很多细节都是错了一次才能发现啊…… 还是不能养成OJ依赖症,交之前先多想想corner case!!! A: 模拟,要特判0啊 ...

  9. [Codeforces #192] Tutorial

    Link: Codeforces #192 传送门 前两天由于食物中毒现在还要每天挂一天的水 只好晚上回来随便找套题做做找找感觉了o(╯□╰)o A: 看到直接大力模拟了 但有一个更简便的方法,复杂度 ...

随机推荐

  1. ES6核心,值得驻足花一天时间来学习

    1.let 和 const 命令 在es5时,只有两种变量声明,var 和function.在es6中新增了四种let和const,以及另外两种声明import和class. 我们先讲解let和con ...

  2. Name That Number 命名那个数字

    1.2.3 Name That Number 命名那个数字 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 183  Solved: 33[Submit][ ...

  3. Vue笔记之模板语法

    插值 比较常用的就是插值,插值就是{{ foobar }}用两个大括号包起来的一个变量,显示的时候会将双大括号标签替换为这个变量的值. 基本的用法就是: <p>{{ message }}& ...

  4. eclipse启动项目

    今天做的任务不多,没有自己写代码,上午看了些文章,下午我司后台给配了配项目环境,全装C盘了..以后有我好受的.. 看着后台操作,修改了N多配置,tomcat.redis.zkServer..Nginx ...

  5. [001] leap_stage

    [Description] There is a number in each stages that indicates the most stages you can leap up. Now, ...

  6. shell 监控磁盘使用率【转】

    方案一: disks=(`df |sed 1d | awk '{print $1,$5}'|tr -d %`) len=${#disks[@]} ;i<=$len;i=i+));do ];the ...

  7. java获取weblogic应用运行路径

    String url = TemplateBuilder(当前类).class.getClassLoader().getResource("").getPath(); String ...

  8. 在Ubuntu上安装Redis MySQL MongoDB memcached Nginx

    1.安装Redis sudo apt-get install redis-server 2.安装MySQL sudo apt-get install mysql-server 3.安装MongoDB ...

  9. 【转载】python import和from import

    import和from import都是将其他模块导入当前模块中. 刚开始一直以为import和from import唯一的区别,就是from import可以少写一些模块名.虽然from XX im ...

  10. linux抓包工具tcpdump基本使用

    tcpdump 是一款灵活.功能强大的抓包工具,能有效地帮助排查网络故障问题. tcpdump 是一个命令行实用工具,允许你抓取和分析经过系统的流量数据包.它通常被用作于网络故障分析工具以及安全工具. ...