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 ...
随机推荐
- setInterval和setTimeout定时器
1,文本框自增(重零开始)每隔一秒递增1 <input type="text" name="name" value="0" id=&q ...
- Sass中常用的函数
字符串函数 To-upper-case() 函数将字符串小写字母转换成大写字母 To-lower-case() 函数 与 To-upper-case() 刚好相反,将字符串转换成小写字母 数字函数 S ...
- 安装 SQL Server 2005 的硬件和软件要求(官方全面)
SQL Server 2005 安装要求 本主题介绍了安装 SQL Server 205 的硬件和软件要求,以及查看安装文档的说明. 硬件和软件要求(32 位和 64 位) 访问 SQL Server ...
- about hadoop-eclipse-plugin used by IDE
Apache Hadoop Development Tools (HDT) is still in development phase. So, no official distribution of ...
- Poco版信号槽
#include "Poco/BasicEvent.h"#include "Poco/Delegate.h"#include <iostream> ...
- 【转】mybatis 获取自增id
转自:http://www.cnblogs.com/rhythmK/p/4047142.html 1.环境: mybatis : 3.2.3 spring-mybatis: 1.2.1 mysql: ...
- UITableView中复用cell显示信息错乱
UITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件.上面主要是一个个的 UITableViewCell,可以让UITableViewCell响应一些点 ...
- Python连接Redis连接配置
1. 测试连接: Python 2.7.8 (default, Oct 20 2014, 15:05:19) [GCC 4.9.1] on linux2 Type "help", ...
- 最全的JAVA源码整合下载
http://www.360doc.com/content/14/0602/00/11407612_382890953.shtml http://www.360doc.com/content/14/0 ...
- 时区 : America/Mexico_City 中文:美国中部时间(墨西哥城) 的夏令时
方法: (参数为: TimeZone timeZone = TimeZone.getTimeZone("America/Mexico_City"); private static ...