2017北京国庆刷题Day3 afternoon
期望得分:100+0+30=130
实际得分:100+36.5+0=136.5
T3 一个变量写混了,丢了30。。

模拟栈
#include<cstdio>
#include<cstring>
using namespace std;
#define N 10001
char s[N];
int st[N],top;
int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
scanf("%s",s);
int len=strlen(s);
for(int i=;i<len;i++)
if(s[i]=='(') st[++top]=;
else if(s[i]=='[') st[++top]=;
else if(s[i]=='{') st[++top]=;
else if(s[i]==')')
{
if(st[top]==) top--;
else { printf("Wrong");return ; }
}
else if(s[i]==']')
{
if(st[top]==) top--;
else { printf("Wrong"); return ; }
}
else
{
if(st[top]==) top--;
else { printf("Wrong"); return ; }
}
if(top) printf("Wrong");
else printf("OK");
return ;
}


设直线解析式为 y=(-n/m)* x+n
整理,得:n * x + m * y - n * m = 0
点(b,a)到直线的距离为:| b * n + a * m - n * m | / L
(L : 根号下(n^2 + m^2)=L)
棺材能够在这里拐弯
直观上感受就是棺材拐弯的全程不被点(b,a)卡住
所以 最优解 是 b * n + a * m - n * m / L 的最小值
为什么这里把绝对值去掉?
因为 当式子<0 时,直线到了点的右上方,就是不合法解,此时棺材不能通过
单峰函数求最小值,三分法每次去掉大的一部分
注意特判直接横着/竖着就能拖过去的情况
#include<algorithm>
#include<cstdio>
#include<cmath> using namespace std;
const double eps=1e-; int a,b,l; double f(double n)
{
double m=sqrt(1.0*l*l-n*n);
return (b*n+a*m-n*m)/l;
} int main()
{
freopen("b.in","r",stdin);
freopen("b.out","w",stdout);
scanf("%d%d%d",&a,&b,&l);
if(a>=l && b>=l) { printf("%d.0000000",l); return ; }
if(a>=l) { printf("%d.0000000",b); return ; }
if(b>=l) { printf("%d.0000000",a); return ; }
double L=,R=l,ans=-1e18,mid1,mid2,t1,t2;
int T=;
while(T--)
{
mid1=(R-L)/+L; mid2=L+R-mid1;
t1=f(mid1); t2=f(mid2);
if(t1< || t2<) { printf("My poor head =("); return ; }
if(t1<t2) ans=t1,R=mid2;
else ans=t2,L=mid1;
}
printf("%.7lf",ans);
}

递归回溯时贪心
如果当前点的分支个数>=2,那么断掉它与父节点的边,子节点中只留两个最优
所以 ans+=分支个数-2+1
加1是因为还要断掉与父节点的连边
但是如果是递归的根节点,就是ans+=分支个数-2
如果当前只有一个分支,那就不用断,仍然是它的父节点的一个分支
最终的答案就是ans*2+1
*2是因为断掉一个,相应的就要添加一条
+1是最后要形成一个环
#include<cstdio>
#include<iostream> #define N 100001 using namespace std; int front[N],nxt[N<<],to[N<<],tot;
int ans; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} void add(int u,int v)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot;
} int dfs(int x,int f)
{
int sum=;
for(int i=front[x];i;i=nxt[i])
if(to[i]!=f) sum+=dfs(to[i],x);
if(sum>=)
{
if(x==) ans+=sum-;
else ans+=sum-;
return ;
}
return ;
} int main()
{
freopen("c.in","r",stdin);
freopen("c.out","w",stdout);
int n,u,v;
read(n);
for(int i=;i<n;i++) read(u),read(v),add(u,v);
dfs(,);
printf("%d",ans*+);
}
2017北京国庆刷题Day3 afternoon的更多相关文章
- 2017北京国庆刷题Day1 afternoon
期望得分:100+100+100=300 实际得分:100+100+100=300 T1 一道图论好题(graph) Time Limit:1000ms Memory Limit:128MB 题目 ...
- 2017北京国庆刷题Day5 afternoon
期望得分:100+60+100=260 实际得分:0+60+40=100 设图中有m个环,每个环有si条边,有k条边不在环中 ans= (2^s1 -2)*( 2^s2 -2)* (2^s3 -2)… ...
- 2017北京国庆刷题Day3 morning
期望得分:100+60+0=160 实际得分:100+30+0=130 考场上用的哈希 #include<cstdio> #include<cstring> #include& ...
- 2017北京国庆刷题Day2 afternoon
期望得分:100+100+50=250 实际得分:100+70+50=220 T1 最大值(max) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一 ...
- 2017北京国庆刷题Day4 afternoon
期望得分:100+100+0=200 实际得分:5+0+0=5 每加入一个数,x的因数位置++ 注意:根号x枚举时,如果x是完全平方数,根号x会重复累计2次,要减去 考场上没减,5分 /(ㄒoㄒ)/~ ...
- 2017北京国庆刷题Day6 afternoon
期望得分:100+100+40=240 实际得分:100+0+40=140 二进制拆分.二进制前缀和 #include<cstdio> #include<iostream> u ...
- 2017北京国庆刷题Day7 afternoon
期望得分:100+30+100=230 实际得分:60+30+100=190 排序去重 固定右端点,左端点单调不减 考场上用了二分,没去重,60 #include<cstdio> #inc ...
- 2017北京国庆刷题Day7 morning
期望得分:100+0+100=200 实际得分:100+20+0=120 离散化搞搞 #include<cstdio> #include<iostream> #include& ...
- 2017北京国庆刷题Day2 morning
期望得分:100+100+40=240 实际得分:100+40+0=140 T1 一道图论神题(god) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK ...
随机推荐
- 第三周pspo过程文档
团队协作: 日期/任务 听课 编写程序 阅读相关书籍 日总计 周一 110 60 ...
- PHP 函数总结
感觉对函数了解的不够深,从头到尾梳理一遍(更新中....) 1,class_exists(),interface_exists(),method_exists(),get_class(),get_pa ...
- Traffic Steering for Service Function Chaining
Introduction 目前通过vlan标签来把流量引向对应的sfc 以前的sfc静态(SFs相邻组成SFC),有了sdn之后具有动态性.(SFs不需要彼此相邻.将流量动态地导向所需的SFs.) 流 ...
- [二叉查找树] 1115. Counting Nodes in a BST (30)
1115. Counting Nodes in a BST (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- CCF——数列分段201509-1
问题描述 给定一个整数数列,数列中连续相同的最长整数序列算成一段,问数列中共有多少段? 输入格式 输入的第一行包含一个整数n,表示数列中整数的个数. 第二行包含n个整数a1, a2, …, an,表示 ...
- 模板CodeTemplate
/** * @author:dubbo@xxxx.com * @date: ${date} ${time} * @version: V1.0 * @review: dubbo/${date} ${ti ...
- SQL中INNER JOIN、LEFT JOIN、RIGHT JOIN、FULL JOIN区别
sql中的连接查询有inner join(内连接).left join(左连接).right join(右连接).full join(全连接)四种方式,它们之间其实并没有太大区别,仅仅是查询出来的结果 ...
- click()、bind()、live()和delegate()方法
我之前使用click()比较多,又来因为网页内容需要前端生成用了live().有的时候使用click()和bind()分不清楚该怎么试用.查了很多资料.测试了很多次,自己明白了. 总结如下:代码注释很 ...
- "流量监管"和"流量整形"的区别
"流量监管" (Traffic Policing) 就是对流量进行控制,通过监督进入交换机端口的流量速率,对超出部分的流量进行"惩罚" (采用监管方式时是直接丢 ...
- 【转】实现虚拟机VMware上linux与windows互相复制与粘贴
1.点击虚拟机-->安装vm tool 2.完成后在系统桌面会出现一个tar文件,解压到tmp目录 下 3.终端cd到该文件夹下,执行./vmware-install.pl 一路回车到底.4.重 ...