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 中 Array.from() 不能得到的数组元素是 undefined 或是空数组

    本文地址:http://www.cnblogs.com/veinyin/p/7944072.html  正确格式 let json = { '0': 'Waaaa~', '1': 'Hello,', ...

  2. 通过jquery.validate.js校验表单字段是否合法

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  3. 【洛谷 P3648】 [APIO2014]序列分割 (斜率优化)

    题目链接 假设有\(3\)段\(a,b,c\) 先切\(ab\)和先切\(bc\)的价值分别为 \(a(b+c)+bc=ab+bc+ac\) \((a+b)c+ab=ab+bc+ac\) 归纳一下可以 ...

  4. 【leetcode 简单】第十三题 最大子序和

    给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输出: 6 解释: 连续子数组 ...

  5. 详解H5中的history单页面,手动实现单页面开发,细说h5单页面原理

    就目前来看,前端的单页面开发占了很大一部分,一方面无刷新的切换增强了体验,并且浏览器记录依然存在,前进后退都没问题,在之前我们通地址栏中的hash改变来触发onhashchange方法来实现单页面应用 ...

  6. discuz 积分按日重新计算,(摒弃以前24小时计算)

    修改\source\module\forum\forum_misc.php将 foreach(C::t('forum_ratelog')->fetch_all_sum_score($_G['ui ...

  7. AngularJs 文件上传(实现Multipart/form-data 文件的上传)

    <!-- 上传yml文件 --> <div class="blackBoard" ng-show="vm.showUpop==true"> ...

  8. SyntaxError: Missing parentheses in call to 'print' 这个错误原因是Python版本问题

    问题 print "www.baidu.com"           Python2 print ("www.baidu.com")     Python3 出 ...

  9. 2017百度春招<有趣的排序>

    题目 度度熊有一个N个数的数组,他想将数组从小到大排好序,但是萌萌的度度熊只会下面这个操作:任取数组中的一个数然后将它放置在数组的最后一个位置.问最少操作多少次可以使得数组从小到大有序? #inclu ...

  10. java基础8 构造函数和构造代码块

    一.构造函数 1 构造函数的作用 给对应的对象进行初始化. 2 构造函数的格式 修饰符 函数名(形式参数){ //函数名就是类名 函数体 } 举例说明: class Perosn{ private i ...