2012 Asia JinHua Regional Contest
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的更多相关文章
- 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) ...
- HDU 4436 str2int(后缀自动机)(2012 Asia Tianjin Regional Contest)
Problem Description In this problem, you are given several strings that contain only digits from '0' ...
- 2012 Asia Chengdu Regional Contest
Browsing History http://acm.hdu.edu.cn/showproblem.php?pid=4464 签到 #include<cstdio> #include&l ...
- 2012 Asia Hangzhou Regional Contest
Friend Chains http://acm.hdu.edu.cn/showproblem.php?pid=4460 图的最远两点距离,任意选个点bfs,如果有不能到的点直接-1.然后对于所有距离 ...
- HDU 4433 locker 2012 Asia Tianjin Regional Contest 减少国家DP
意甲冠军:给定的长度可达1000数的顺序,图像password像锁.可以上下滑动,同时会0-9周期. 每个操作.最多三个数字连续操作.现在给出的起始序列和靶序列,获得操作的最小数量,从起始序列与靶序列 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 无法解决 equal to 运算中 "Chinese_PRC_CI_AS" 和 "Chinese_PRC_90_CI_AI" 之间的排序规则冲突。的解决方法
在SQL SERVICE的查询的时候遇到了“无法解决 equal to 运算中 "Chinese_PRC_CI_AS" 和 "Chinese_PRC_90_CI_AI&q ...
- Hadoop集群错误
1.Hadoop集群所有的DataNode都启动不了解决办法 删除从节点.../usr/hadoop/tmp/dfs/ 下内容,再重新格式化namenode
- ios警告:Category is implementing a method which will also be implemented by its primary class 引发的相关处理
今天在处理项目中相关警告的时候发现了很多问题,包括各种第三方库中的警告,以及各种乱七八糟的问题 先说说标题中的问题 Category is implementing a method which ...
- (转)每天一个linux命令(46):vmstat命令
vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存.进程.CPU活动进行监控.他是对系统的整体情况进行统计,不足之处是无法对某个进程进行深 ...
- how to debug thread cpu 100%
when we write a program, cpu and memory usages are very important to indicate the stability of the p ...
- n盏灯亮灭问题
前几天看了华为的一个上机操作题,讲得是n盏灯亮灭问题,本质上还是数学问题,感觉很有趣,和大家分享一下,问题描述如下: 有n盏灯排成一排,依次标号1,2,…,n,每盏灯都有一根拉线开关,最初电灯都是关着 ...
- Linux美化——终端提示符
1. PS1变量简介[1] PS1是Linux终端用户的一个环境变量,用来说明命令行提示符的设置. 可以使用 man bash命令查看bash手册,找到该变量支持的特殊字符,以及这些特殊字符的意义: ...
- const char *p、char const *p、char * const p的区别?
const char *p和char const *p是一样的,都表示定义一个指向字符常量的指针,指针的内容(字符)不可变.char * const p表示一个指向字符的指针常量,字符可以改变,但是指 ...
- 淘宝店铺应用android源码
一个淘宝店铺的app 界面模仿蘑菇街 完结版很多朋友想知道web端 我发上来 是用thinkphp框架 懂的同学拿去研究 ,之前做的前台 现在基本上不能用 就看个后台就好了 也比较简单 我放上来 大家 ...
- Code Review的一些典型内容
如下是Code Review中一些典型的内容: 一.常规项: 1.代码能够工作么?它有没有实现预期的功能,逻辑是否正确等. 2.所有的代码是否简单易懂? 3.代码符合你所遵循的编程规范么?这通常包括大 ...