Draw Something http://acm.hdu.edu.cn/showproblem.php?pid=4450

o(n)统计输入每个数的平方和。

 #include<cstdio>
int main(){
int n,x;
while(~scanf("%d",&n),n){
int ans=;
while(n--){
scanf("%d",&x);
ans+=x*x;
}
printf("%d\n",ans);
}
return ;
}

Physical Examination http://acm.hdu.edu.cn/showproblem.php?pid=4442

有n个任务要完成,每个任务有x,y两个权值。完成某个任务所需的时间是x+t*y,其中t是当前的时间,也就是之前所有任务的时间总和。为了使总时间小。

贪心的算法。

考虑x,x不论放哪里,对于当前任务的贡献值都是x,但是对后面所有任务的t都有贡献,所以x越小越先做,这样后面t就会相对较小,使得后面任务所需时间也小。

考虑y,y放哪里,对当前任务贡献值是t*y,也就是说y越大,越要先做,因为先做的t肯定比后做的小,而且这样也会使得对之后的贡献值减小。

综上所诉,x越小y越大,那么越优先,定义一个优先系数用x/y表示,系数越小,越先做。因为可能有除不尽的情况,我又不想用double,等下精度又gg,所以转化了一下。

a.x/a.y < b.x/b.y   =>    a.x*b.y <b.x*a.y

o(n*log(n))

 #include<cstdio>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const int M=;
const int mod=***;
struct G{
LL x,y;
friend bool operator <(G a,G b){
return a.x*b.y<b.x*a.y;
}
}p[M];
int main(){
int n,x;
while(~scanf("%d",&n),n){
for(int i=;i<n;i++){
scanf("%I64d%I64d",&p[i].x,&p[i].y);
}
sort(p,p+n);
LL ans=,now=;
for(int i=;i<n;i++){
ans+=p[i].x+now*p[i].y;
ans%=mod;
now=ans;
}
printf("%I64d\n",ans);
}
return ;
}

Dressing http://acm.hdu.edu.cn/showproblem.php?pid=4451

根据输入p=10^6处理出两两之间是否有关系,有关系就不能匹配。然后n^2的处理出每一个pants能匹配几个shoes,然后n^2的枚举clothes 和 pants,通过之前处理的值可以直接算出包含这对衣服裤子的匹配数。

总的复杂度还是o(n^2)

 #include<cstdio>
#include<cstring>
#define mt(a,b) memset(a,b,sizeof(a))
const int M=;
int sum[M];
bool ctop[M][M],ptos[M][M];
char a[],b[];
int main(){
int n,m,k,p,x,y;
while(~scanf("%d%d%d",&n,&m,&k),n|m|k){
scanf("%d",&p);
mt(ctop,);
mt(ptos,);
while(p--){
scanf("%s%d%s%d",a,&x,b,&y);
if(a[]=='c'){
ctop[x][y]=true;
}
else{
ptos[x][y]=true;
}
}
mt(sum,);
for(int i=;i<=m;i++){
for(int j=;j<=k;j++){
if(!ptos[i][j]){
sum[i]++;
}
}
}
int ans=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(!ctop[i][j]){
ans+=sum[j];
}
}
}
printf("%d\n",ans);
}
return ;
}

Running Rabbits http://acm.hdu.edu.cn/showproblem.php?pid=4452

o(n)的模拟题。题目怎么说怎么做。题目说11,和nn有两人有初始方向,告诉你每秒的速度,几秒左转一次,撞墙了就向后转把剩余步数走完,两个相遇在同一个点交换方向,万一正好要左转那就忽略这次左转。

 #include<cstdio>
#include<algorithm>
using namespace std;
struct G{
int x,y,dir,s,t;
}A,B;
int change(int x){
if(x==) return ;
if(x==) return ;
if(x==) return ;
if(x==) return ;
}
void turnleft(G &C){
C.dir=change(C.dir);
}
int getdir(char c){
if(c=='E') return ;
if(c=='W') return ;
if(c=='N') return ;
if(c=='S') return ;
}
int dx[]={,,-,};
int dy[]={,-,,};
int n,k;
int really(int x){
if(x>=&&x<=n) return x;
if(x>n) return n-(x-n);
if(x<) return +(-x);
}
void onestep(G &C){
int tx=C.x+dx[C.dir]*C.s;
int ty=C.y+dy[C.dir]*C.s;
C.x=really(tx);
C.y=really(ty);
if(C.x!=tx||C.y!=ty){
C.dir^=;
}
}
int main(){
char op[];
while(~scanf("%d",&n),n){
scanf("%s%d%d",op,&A.s,&A.t);
A.dir=getdir(op[]);
A.x=A.y=;
scanf("%s%d%d",op,&B.s,&B.t);
B.dir=getdir(op[]);
B.x=B.y=n;
scanf("%d",&k);
for(int i=;i<=k;i++){
onestep(A);
onestep(B);
if(A.x==B.x&&A.y==B.y){
swap(A.dir,B.dir);
continue;
}
if(!(i%A.t)) turnleft(A);
if(!(i%B.t)) turnleft(B);
}
printf("%d %d\n%d %d\n",A.x,A.y,B.x,B.y);
}
return ;
}

Crazy Tank http://acm.hdu.edu.cn/showproblem.php?pid=4445

有n个炮弹,每个炮弹有各自的速度,炮的角度可以任意选,但是选了之后就不能改变了。敌方有区间L1R1,我方有区间L2R2。现在问在保证没有炮弹进入我方的情况下,最多能有几个炮弹进入敌方区间。

算法,暴力枚举角度θ,算这个角度下满足题意有几个。枚举了1000个角度过了,复杂度200*1000*testcase。

抛物线速度时间都是对称的。枚举的是炮和y轴的角度θ。在这个角度下水平速度Vx=Vi*sin(θ) 垂直速度 Vy=Vi*cos(θ)

达到最高点的时间 t1=Vy/g   g=9.8重力加速度

对于对称点到地面  距离H=Vy*t2+1/2*g*t2*t2

解出t2   总时间 t = 2*t1+t2     水平位移  s=Vx*t

 #include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double eps=1e-;
const double pi=acos(-1.0);
const double g=9.8;
const int M=;
double v[M],H,L1,R1,L2,R2;
void solve2ci(double A,double B,double C,double &x1,double &x2){
double delta=B*B-*A*C;
x1=(-B+sqrt(delta))/(*A);
x2=(-B-sqrt(delta))/(*A);
}
int main(){
int n;
while(~scanf("%d",&n),n){
scanf("%lf%lf%lf%lf%lf",&H,&L1,&R1,&L2,&R2);
for(int i=;i<n;i++){
scanf("%lf",&v[i]);
}
double add=180.0/;
double xita,Vx,Vy,t1,t2,t,s,x1,x2,A=0.5*g,B,C=-H;
int ans=;
for(double x=;x<;x+=add){
xita=x*pi/;
int sum=;
for(int i=;i<n;i++){
Vx=v[i]*sin(xita);
Vy=v[i]*cos(xita);
B=Vy;
solve2ci(A,B,C,x1,x2);
t1=Vy/g;
t2=max(x1,x2);
t=t1+t1+t2;
s=Vx*t;
if(L2-eps<s&&s<R2+eps){
sum=;
break;
}
if(L1-eps<s&&s<R1+eps){
sum++;
}
}
ans=max(ans,sum);
}
printf("%d\n",ans);
}
return ;
}

end

2012 Asia JinHua Regional Contest的更多相关文章

  1. HDU-4432-Sum of divisors ( 2012 Asia Tianjin Regional Contest )

    Sum of divisors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 4436 str2int(后缀自动机)(2012 Asia Tianjin Regional Contest)

    Problem Description In this problem, you are given several strings that contain only digits from '0' ...

  3. 2012 Asia Chengdu Regional Contest

    Browsing History http://acm.hdu.edu.cn/showproblem.php?pid=4464 签到 #include<cstdio> #include&l ...

  4. 2012 Asia Hangzhou Regional Contest

    Friend Chains http://acm.hdu.edu.cn/showproblem.php?pid=4460 图的最远两点距离,任意选个点bfs,如果有不能到的点直接-1.然后对于所有距离 ...

  5. HDU 4433 locker 2012 Asia Tianjin Regional Contest 减少国家DP

    意甲冠军:给定的长度可达1000数的顺序,图像password像锁.可以上下滑动,同时会0-9周期. 每个操作.最多三个数字连续操作.现在给出的起始序列和靶序列,获得操作的最小数量,从起始序列与靶序列 ...

  6. HDU 4468 Spy(KMP+贪心)(2012 Asia Chengdu Regional Contest)

    Description “Be subtle! Be subtle! And use your spies for every kind of business. ”― Sun Tzu“A spy w ...

  7. HDU 4467 Graph(图论+暴力)(2012 Asia Chengdu Regional Contest)

    Description P. T. Tigris is a student currently studying graph theory. One day, when he was studying ...

  8. HDU 4441 Queue Sequence(优先队列+Treap树)(2012 Asia Tianjin Regional Contest)

    Problem Description There's a queue obeying the first in first out rule. Each time you can either pu ...

  9. HDU 4433 locker(DP)(2012 Asia Tianjin Regional Contest)

    Problem Description A password locker with N digits, each digit can be rotated to 0-9 circularly.You ...

随机推荐

  1. STP详解

    STP详解 Write From YangWj Wednesday, March 5, 2014 一. 生成树协议 STP的主要任务是阻止在第2层网络(网桥或交换机)产生网络环路,它警惕的监视着网络中 ...

  2. 【学习笔记】【C语言】三目运算符

    1.N目运算符 像逻辑非(!).负号(-)这种只连接一个数据的符号,称为“单目运算符”,比如!5.-5.像算术运算符.关系运算符.逻辑运算符这种连接二个数据的负号,称为“双目运算符”,比如6+7.8* ...

  3. 20141201--测试 jQuery

    测试 JavaScript 框架库 - jQuery jQuery 是一个 JavaScript 库. 引用 jQuery <!DOCTYPE html> <html> < ...

  4. [Silverlight] Visual Studio2010不能安装Silverlight4_Tools,提示语言不一致

    今天在装Silverlight4_Tools时出现“必须先安装与 Silverlight Tools 4 语言版本相一致的 Visual Studio 2010.Visual Web Develope ...

  5. CityEngine2012(32位)安装

    今天下午把CityEngine2012装好了,既然Esri大力推CityEngine作为其三维建模软件,那就学习一下,还好没花多长时间搞定破解版,以前装Erdas,南方CASS,AutoCAD那些该死 ...

  6. C语言成绩测试 ,水仙花数,打印星图

    #include <stdio.h>//输入输出头文件 #include<string.h> #include<stdlib.h> //局部被调用函数1 成绩检测 ...

  7. 防止双击选中html中文字

    在开发过程中很常用的会给<span></span>等内联元素增加一个onlick事件,但是经常发生的一件事情就是点击的时候,选中了span中的字体:倒是不影响主逻辑,但是很难受 ...

  8. ADO.NET笔记——SQL注入攻击

    相关知识: 可以通过字符串的拼接来构造一个SQL命令字符串,但是SQL命令字符串的拼接确是造成“SQL注入攻击”的重要原因. 考虑下列例子:从ProductCategory表中检索出Name为“Bik ...

  9. jquery 在页面中三种写法

    jQuery 分 2 个系列版本 1.x 与 2.x,主要的区别在于 2.x 不再兼容 IE6.7.8浏览器,这样做的目的是为了兼容移动端开发.由于减少了一些代码,使得该版本比 jQuery 1.x ...

  10. SQL Server 2008中新增的变更数据捕获(CDC)和更改跟踪

    来源:http://www.cnblogs.com/downmoon/archive/2012/04/10/2439462.html  本文主要介绍SQL Server中记录数据变更的四个方法:触发器 ...