8-10-Exercise
A.ZOJ 3203 Light Bulb
这道题............哎~既可以用数学直接推导出来,也可以三分求,还可以二分求~~~~
NO1.数学公式
这种方法搞的不是很清楚..........T T .........什么时候几何这么烂了.................= =心都碎了~
感觉影子的最长的长度会在h,h*D/H,以及另外的某个数中(D+H-sqrt((H-h)*D)-(H-h)*D/sqrt((H-h)*D))........可是判断条件.......ORZ木有弄清~
代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std; int main()
{
int T;
double H,h,D;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf",&H,&h,&D);
double temp=sqrt((H-h)*D);
double temp2=(H-h)*D/H;
if(temp>=D)printf("%.3lf\n",h);
else if(temp<temp2)printf("%.3lf\n",h*D/H);
else
{
double ans=D+H-temp-(H-h)*D/temp;
printf("%.3lf\n",ans);
}
}
return ;
}
//memory:188KB time:0ms
NO2.三分~
对在墙上的影子进行三分~
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; double H,h,D; double shadow(double x)
{
return (x+D*(h-x)/(H-x));
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf",&H,&h,&D);
double l,left=,right=h,mid,midd;
while(right-left>1e-)
{
mid=(left+right)/;
midd=(mid+right)/;
if(shadow(mid)>shadow(midd))
right=midd;
else
left=mid;
}
printf("%.3lf\n",shadow(right));
}
return ;
}
//memory:188KB time:0ms
B.POJ 3974 Palindrome
由于数字较大,暴力绝对超时~
具体题解也是看的网上的博客~要用到一个叫Manancher的算法~~~~链接:http://www.cnblogs.com/lv-2012/archive/2012/11/15/2772268.html
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std; const int MAX=;
char a[MAX],str[MAX<<];
int r[MAX<<],Rmax; void Manancher()
{
int i,j,maxx;
int n=strlen(a);
memset(str,'#',sizeof(str));
for(i=;i<n;i++)
str[(i+)<<]=a[i];
n=(n+)<<;
str[n]='$';
Rmax=j=maxx=;
for(i=;i<n;i++)
{
if(i<maxx)
r[i]=min(r[*j-i],maxx-i);
else r[i]=;
while(str[i-r[i]]==str[i+r[i]])
{
r[i]++;
}
if(Rmax<r[i])
Rmax=r[i];
if(r[i]+i>maxx)
{
j=i;
maxx=r[i]+i;
}
}
} int main()
{
int t=;
while(~scanf("%s",a)!=EOF && a[]!='E')
{
Manancher();
printf("Case %d: %d\n",t++,Rmax-);
}
return ;
}
//memory:10936KB time;188ms
C.HDU 1394 Minimum Inversion Number
肿么说呢........哎~比赛前刚做的这道题........让人淡淡的忧桑啊.......
再另一篇博客写的有这道题.............链接:忧桑啊~
代码(就只发.....暴力.....线段树在链接里有):
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; int a[]; int main()
{
int n,i,j,re,sum,k;
while(~scanf("%d",&n))
{
for(i=;i<n;i++)
{
scanf("%d",&a[i]);
a[i+n]=a[i];
}
sum=;
for(j=;j<n;j++)
{
for(k=j+;k<n;k++)
if(a[k]<a[j])
sum++;
}
re=sum;
for(i=;i<n;i++)
{
sum+=n--*a[i];
re=min(sum,re);
}
printf("%d\n",re); }
return ;
}
//memory:268KB time:265ms
D.HDU 3400 Line belt
.......
E.HDU 2152 Fruit
水水的题目~
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; int c1[],c2[]; int main()
{
int n,m,i,j,a[],b[],k;
while(~scanf("%d%d",&n,&m))
{
for(i=;i<=n;i++)
scanf("%d%d",&a[i],&b[i]);
memset(c1,,sizeof(c1));
memset(c2,,sizeof(c2));
c1[]=;
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
for(k=a[i];k+j<=m && k<=b[i];k+=)
{
c2[k+j]+=c1[j];
}
for(j=;j<=m;j++)
{
c1[j]=c2[j];
c2[j]=;
}
}
printf("%d\n",c1[m]);
}
return ;
}
//memory:252KB time:0ms
8-10-Exercise的更多相关文章
- Android布局优化之include、merge、ViewStub的使用
本文针对include.merge.ViewStub三个标签如何在布局复用.有效减少布局层级以及如何可以按需加载三个方面进行介绍的. 复用布局可以帮助我们创建一些可以重复使用的复杂布局.这种方式也意味 ...
- MIT 6.828 Lab04 : Preemptive Multitasking
目录 Part A:Multiprocessor Support and Cooperative Multitasking Multiprocessor Support 虚拟内存图 Exercise ...
- MIT 6.828 JOS学习笔记13 Exercise 1.10
Lab 1 Exercise 10 为了能够更好的了解在x86上的C程序调用过程的细节,我们首先找到在obj/kern/kern.asm中test_backtrace子程序的地址, 设置断点,并且探讨 ...
- 《MIT 6.828 Lab 1 Exercise 10》实验报告
本实验的网站链接:MIT 6.828 Lab 1 Exercise 10. 题目 Exercise 10. To become familiar with the C calling conventi ...
- Introduction to Differential Equations,Exercise 1.1,1.5,1.6,1.8,1.9,1.10
As noted,if $z=x+iy$,$x,y\in\mathbf{R}$,then $|z|=\sqrt{x^2+y^2}$ is equivalent to $|z|^2=z\overline ...
- MIT 6.828 JOS学习笔记11 Exercise 1.8
Exercise 1.8 我们丢弃了一小部分代码---即当我们在printf中指定输出"%o"格式的字符串,即八进制格式的代码.尝试去完成这部分程序. 解答: 在这个练 ...
- MIT 6.828 JOS学习笔记10. Lab 1 Part 3: The kernel
Lab 1 Part 3: The kernel 现在我们将开始具体讨论一下JOS内核了.就像boot loader一样,内核开始的时候也是一些汇编语句,用于设置一些东西,来保证C语言的程序能够正确的 ...
- 使用 Swift 在 iOS 10 中集成 Siri —— SiriKit 教程
下载 Xcode 8,配置 iOS 10 和 Swift 3 (可选)通过命令行编译 除 非你想使用命令行编译,使用 Swift 3.0 的工具链并不需要对项目做任何改变.如果你想的话,打开 Xcod ...
- Stanford coursera Andrew Ng 机器学习课程编程作业(Exercise 2)及总结
Exercise 1:Linear Regression---实现一个线性回归 关于如何实现一个线性回归,请参考:http://www.cnblogs.com/hapjin/p/6079012.htm ...
- stanford coursera 机器学习编程作业 exercise 3(逻辑回归实现多分类问题)
本作业使用逻辑回归(logistic regression)和神经网络(neural networks)识别手写的阿拉伯数字(0-9) 关于逻辑回归的一个编程练习,可参考:http://www.cnb ...
随机推荐
- SQL Server中count(*), count(col), count(1)的对比
让我们先看一下BOL里面对count(*)以及count(col)的说明: COUNT(*) 返回组中的项数.包括 NULL 值和重复项. COUNT(ALL expression) 对组中的每一行都 ...
- express开发实例
express获取参数有三种方法:官网介绍如下 Checks route params (req.params), ex: /user/:id Checks query string params ( ...
- 在 Linux 命令行中使用和执行 PHP 代码
PHP是一个开源服务器端脚本语言,最初这三个字母代表的是“Personal Home Page”,而现在则代表的是“PHP:Hypertext Preprocessor”,它是个递归首字母缩写.它是一 ...
- 计划任务实现定时备份mysql数据库
1.linux平台 30 3 * * * sh /data/tools/mysqlbackup.sh 每天3点半备份数据库mysqlbackup.sh(备份最近5天的数据): #设置数据库名,数据库 ...
- ThinkPHP下使用Ueditor
在做课程设计的时候想到用百度的Ueditor,可在配置的时候出现了一些问题 Ueditor感觉不是很难,以前有个人定制的,现在取消了这项服务,但是我们可以自己进行配置 下载地址:http://uedi ...
- PHP源代码分析(第一章):Zend HashTable详解【转】
转载于http://www.phppan.com/2009/12/zend-hashtable/ 在PHP的Zend引擎中,有一个数据结构非常重要,它无处不在,是PHP数据存储的核心,各种常量.变量. ...
- 【转】ant命令总结
http://feiyeguohai.iteye.com/blog/1295922 ant命令总结 1 Ant是什么? Apache Ant 是一个基于 Java的生成工具. 生成工具在软件开发中用 ...
- nginx 多站点配置方法
关于nginx的多站设置,其实和apache很相似哒. 假设我们已经有两个域名,分别是:www.websuitA.com和www.websuitB.com.并且这两个域名已经映射给了IP为192.16 ...
- 打开网页自动弹出qq客户端
新建js后调用即可,打开网站自动弹出qq对话框,若qq为关闭状态则启动qq,之后弹出对话框. document.write("<iframe src='tencent://messag ...
- BZOJ 1715: [Usaco2006 Dec]Wormholes 虫洞
Description John在他的农场中闲逛时发现了许多虫洞.虫洞可以看作一条十分奇特的有向边,并可以使你返回到过去的一个时刻(相对你进入虫洞之前).John的每个农场有M条小路(无向边)连接着N ...