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 ...
随机推荐
- HDU 5211 Mutiple 水题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5211 题解: 1.筛法: #include<iostream> #include< ...
- swift - tabBar图片设置的一些注意点
图片大小尺寸 刚刚开始接触的话,从美工那边拿来的图标大小一般都是偏大的,就像这样: 在此建议,tabBar的图标大小可以是32*32,个人感觉效果不错 图片的颜色问题 如上图所示,该图标的期望颜色(也 ...
- lintcode-480-二叉树的所有路径
480-二叉树的所有路径 给一棵二叉树,找出从根节点到叶子节点的所有路径. 您在真实的面试中是否遇到过这个题? Yes 样例 给出下面这棵二叉树: 所有根到叶子的路径为: [ "1-> ...
- lintcode-425-电话号码的字母组合
425-电话号码的字母组合 Given a digit string excluded 01, return all possible letter combinations that the num ...
- Servlet中常用对象及API类之间的关系
Servlet最常用的对象: 请求对象:ServletRequest和HttpServletRequest,通过该对象获取来自客户端的请求信息 响应对象:ServletResponse和HttpSer ...
- vsftpd 安全性能工具
vsftpd实战(服务端192.168.23.12,客户端192.168.23.11) 1:安装vsftpdyum install -y vsftpd 2:客户端安装lftpyum install - ...
- Vue.js 上传文件(后台使用.net)
页面部分 <div id="app"> <form id="myform"> <input type="file&quo ...
- BZOJ 2186 沙拉公主的困惑(预处理逆元+欧拉函数)
题意:求1-n!里与m!互质的数有多少?(m<=n<=1e6). 因为n!%m!=0,所以题目实际上求的是phi(m!)*n!/m!. 预处理出这些素数的逆元和阶乘的模即可. # incl ...
- Java虚拟机的内存管理
众所周知,Java程序员写的代码是没有办法控制Java对象的内存释放的,完全有JVM暗箱操作. 虽然程序员把内存的释放的任务都交给了Java虚拟机,但是并不代表Java程序就不存在内存泄漏. 反而,某 ...
- Tomcat+JDK安装和配置
Tomcat+JDK安装和配置 一.打开FlashFXP软件,建立连接,选择需要的包,右击传输到 /home/guest中 二.进入到:cd /home/guest中,对tomcat包进行解压 三.将 ...