a

【问题描述】
你是能看到第一题的 friends 呢。
——hja
给你一个只有小括号和中括号和大括号的括号序列,问该序列是否合法。
【输入格式】
一行一个括号序列。
【输出格式】
如果合法,输出 OK,否则输出 Wrong。
【样例输入】
[(])
【样例输出】
Wrong
【数据范围与规定】
70%的数据,1 ≤ ? ≤ 100。
对于100%的数据,1 ≤ ? ≤ 10000,所有单词由大写字母组成。

#include<iostream>
#include<cstring>
#include<cstdio>
#define maxn 10010
using namespace std;
int top;
char ch[maxn],st[maxn];
int main(){
//freopen("Cola.txt","r",stdin);
freopen("a.in","r",stdin);freopen("a.out","w",stdout);
scanf("%s",ch+);
int len=strlen(ch+);
for(int i=;i<=len;i++){
if(ch[i]=='('||ch[i]=='['||ch[i]=='{')st[++top]=ch[i];
else if(ch[i]==')'){
if(top==||st[top]!='('){
printf("Wrong");
return ;
}
else top--;
}
else if(ch[i]==']'){
if(top==||st[top]!='['){
printf("Wrong");
return ;
}
else top--;
}
else if(ch[i]=='}'){
if(top==||st[top]!='{'){
printf("Wrong");
return ;
}
else top--;
}
}
if(top!=)printf("Wrong");
else printf("OK");
fclose(stdin);fclose(stdout);
return ;
}

100分 栈模拟

b

【问题描述】
你是能看到第二题的 friends 呢。
——laekov
Yjq 想要将一个长为?宽为?的矩形棺材(棺材表面绝对光滑,所以棺材可
以任意的滑动)拖过一个 L 型墓道。
如图所示,L 型墓道两个走廊的宽度分别是?和?,呈 90°,并且走廊的长
度远大于?。
现在 Hja 想知道对于给定的?,?,?,最大的?是多少,如果无论如何棺材都
不可能通过,则输出"My poor head =("
【输入格式】
第一行三个用空格分隔的整数?,?,?,意义如题目所示。
【输出格式】
输出最大的可能的?,保留七位小数,如果无论如何棺材都不可能通过,则
输出"My poor head =("。
【样例输入 1】
2 2 1
【样例输出 1】
1.0000000
P100 zhxb
第 4 页 共 5 页
【样例输入 2】
2 2 2
【样例输出 2】
2.0000000
【样例输入 3】
2 2 3
【样例输出 3】
1.3284271
【样例输入 4】
2 2 6
【样例输出 4】
My poor head =(
【数据范围与规定】
对于100%的数据,1 ≤ ?,?,? ≤ 10 4 。

#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int a,b,l;
double q,e,ans;
int main(){
freopen("b.in","r",stdin);freopen("b.out","w",stdout);
scanf("%d%d%d",&a,&b,&l);
q=sqrt(a*a+b*b);
e=l*1.0/;
ans=min(double(l),q-e);
if(l<=b)ans=max(ans,min(double(a),double(l)));
if(ans<)printf("My poor head =(");
else printf("%.7lf",ans);
fclose(stdin);fclose(stdout);
return ;
}

18分 乱搞

/*
两种情况:
1.在拐角处被卡:以最左下角的点为原点,用矩形与坐标轴相交的两个点可以求出矩形一边的直线的方程,通过右上方点到这个直线的距离可以求出此时的宽度,然后可以转换成一个以宽度为因变量的函数,这个函数是一个单峰函数,用三分求解
2.在拐角处垂直向上移动,直接输出b
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int a,b,l;
double get(double v1)
{
double v2=sqrt(l*l-v1*v1);
if (a*v1+b*v2<v1*v2) return -1e+;
else return (a*v1+b*v2-v1*v2)/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\n",l);
else
{
if (a>=l) printf("%d.0000000\n",b);
else
{
if (b>=l) printf("%d.0000000\n",a);
else
{
double lv=0.0,rv=l;
for (int c=;c<=;c++)
{
double m1=(rv-lv)/3.0+lv;
double m2=lv+rv-m1;
if (get(m1)<0.0 || get(m2)<0.0)
{
printf("My poor head =(\n");
return ;
}
if (get(m1)<get(m2)) rv=m2;
else lv=m1;
}
printf("%.7lf\n",get(rv));
}
}
}
return ;
}

100分 三分

c

【问题描述】
你是能看到第三题的 friends 呢。
——aoao
树是个好东西,删掉树一条边要 1 的代价,随便再加一条边有 1 的代价,求
最小的代价把树变成环。
【输入格式】
第一行一个整数?,代表树的点数。
接下来? − 1行,每行两个数代表树的一条边。
【输出格式】
一行一个整数代表答案。
【样例输入】
4
1 2
2 3
2 4
【样例输出】
3
【数据规模与约定】
3。
60%的数据,1 ≤ ? ≤ 10。
对于100%的数据,1 ≤ ? ≤ 100000。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100010
using namespace std;
int n,num,ans,root;
int into[MAXN],head[MAXN];
struct node{
int to,pre;
}e[MAXN*];
void add(int from,int to){
e[++num].to=to;
e[num].pre=head[from];
head[from]=num;
}
void dfs(int now,int fa){
for(int i=head[now];i;i=e[i].pre){
int to=e[i].to;
if(to!=fa){
dfs(to,now);
if(into[to]>){
into[now]--;
ans+=(into[to]-)*;
}
}
}
}
int main(){
freopen("c.in","r",stdin);freopen("c.out","w",stdout);
scanf("%d",&n);
for(int i=;i<n;i++){
int u,v;
scanf("%d%d",&u,&v);
add(u,v);add(v,u);
into[u]++;
into[v]++;
}
root=;
for(int i=;i<=n;i++)
if(into[i]==){
root=i;
break;
}
dfs(root,-);
cout<<ans+;
}

100分 贪心+暴力

2017-10-3 清北刷题冲刺班p.m的更多相关文章

  1. 2017-10-4 清北刷题冲刺班p.m

    P102zhx a [问题描述]你是能看到第一题的 friends 呢.——hja两种操作:1.加入一个数.2.询问有多少个数是?的倍数.[输入格式]第一行一个整数?,代表操作数量.接下来?行,每行两 ...

  2. 2017-10-4 清北刷题冲刺班a.m

    P101zhx a [问题描述]你是能看到第一题的 friends 呢.——hjaHja 拥有一套时光穿梭技术,能把字符串以超越光速的速度传播,但是唯一的问题是可能会 GG.在传输的过程中,可能有四种 ...

  3. 2017-10-3 清北刷题冲刺班a.m

    P99zhx a [问题描述]你是能看到第一题的 friends 呢.——hja怎么快速记单词呢?也许把单词分类再记单词是个不错的选择.何大爷给出了一种分单词的方法,何大爷认为两个单词是同一类的当这两 ...

  4. 2017-10-2 清北刷题冲刺班a.m

    一道图论神题 (god) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,只 ...

  5. 2017-10-2 清北刷题冲刺班p.m

    最大值 (max) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一本书,上面有很多有趣的OI问题.今天LYK看到了这么一道题目: 这里有一个长度为n ...

  6. 2017-10-1 清北刷题冲刺班p.m

    一道图论好题 (graph) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图 ...

  7. 2017-10-7 清北刷题冲刺班p.m

    测试 A 同花顺 文件名 输入文件 输出文件 时间限制 空间限制card.cpp/c/pas card.in card.out 1s 512MB题目描述所谓同花顺,就是指一些扑克牌,它们花色相同,并且 ...

  8. 2017-10-7 清北刷题冲刺班a.m

    测试 A 消失的数字 文件名 输入文件 输出文件 时间限制 空间限制del.cpp/c/pas del.in del.out 1s 512MB题目描述现在,我的手上有 n 个数字,分别是 a 1 ,a ...

  9. 2017-10-1 清北刷题冲刺班a.m

    位运算1 (bit) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK拥有一个十进制的数N.它赋予了N一个新的意义:将N每一位都拆开来后再加起来就是N所拥 ...

随机推荐

  1. VS2013修改resource之后产生designer1.cs

    1. Unload project2. Edit the csproj file.3. Search for <LastGenOutput>test1.Designer.cs</La ...

  2. Apache配置负载均衡-实例

    公司两台服务器都安装了tomcat,配置apache作为负载均衡,当一台服务器出现故障时还能保证业务正常运行. Server1:192.168.1.100 Server2:192.168.1.200 ...

  3. Linux-NoSQL之Redis(一)

    1.Redis介绍 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(s ...

  4. java--xml文件读取(DOM)

    1.表现:一“.xml”为扩展名的文件 2.存储:树形结构 3.xml解析应用: 不同应用程序之间的通信-->订票软件和支付软件 不同的平台间通信-->操作系统 不同平台间数据的共享--& ...

  5. codeforces 710A A. King Moves(水题)

    题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...

  6. hdu 3537 Daizhenyang's Coin(博弈-翻硬币游戏)

    题意:每次可以翻动一个.二个或三个硬币.(Mock Turtles游戏) 初始编号从0开始. 当N==1时,硬币为:正,先手必胜,所以sg[0]=1. 当N==2时,硬币为:反正,先手必赢,先手操作后 ...

  7. 【原创】C++实现获取本机机器名及外网IP代码

    上代码: #include "stdafx.h" #include <WINSOCK2.H> #include <urlmon.h> #pragma com ...

  8. bzoj 2553: [BeiJing2011]禁忌 AC自动机+矩阵乘法

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=2553 题解: 利用AC自动机的dp求出所有的转移 然后将所有的转移储存到矩阵中,进行矩阵 ...

  9. 向vivi中加入命令

    在vivi的lib/command.c中添加自己的命令 核心数据结构user_command. typedef struct user_command { const char *name;      ...

  10. POJ1365:质因数分解

    Prime Land Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3590   Accepted: 1623 Descri ...