链接:第四次小练

A.POJ 3094   Quicksum

水题中的水题啊~

直接上代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; char a[]; int main()
{
while()
{
memset(a,,sizeof(a));
gets(a);
if(a[]=='#') break;
int i,j,sum=,k;
int n=strlen(a);
for(i=;i<n;i++)
{
k=a[i]-'A'+;
if(a[i]==' ') k=;
sum+=k*(i+);
}
printf("%d\n",sum);
}
return ;
}

//memory:160KB  time:0ms

B.HDU 1175   连连看

与以前那道逃离迷宫其实很像..................这道题中采用的是先往一个方向走,到没有路了,换一个方向的时候,就是转弯的时候,记录转弯次数~

代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; class Node
{
public:
int x,y,turn;
}q[]; int n,m,a[][],x1,x2,y1,y2,add[][]={{,},{,-},{,},{-,}},hash[][]; int inline push(int x,int y,int turn,int end)
{
Node t;
t.x=x;
t.y=y;
t.turn=turn;
q[end++]=t;
return end;
} bool inline judge(int x,int y) //判断该点是否能走......
{
if(x<=n && x> && y<=m && y> && a[x][y]==)
return true;
else return false;
} bool inline bfs(int x,int y)
{
memset(hash,,sizeof(hash));
int f=,end=;
end=push(x,y,-,end);
hash[x][y]=;
while(f<end)
{
if(q[f].turn>=) return false;
for(int i=;i<;i++)
{
int dx=q[f].x+add[i][];
int dy=q[f].y+add[i][];
int turn=q[f].turn+;
while(judge(dx,dy)||(dx==x2 && dy==y2))
{
if(dx==x2 && dy==y2 && a[dx][dy]==a[x][y])
return true;
if(!hash[dx][dy])
{
hash[dx][dy]=;
end=push(dx,dy,turn,end);
}
dx+=add[i][]; //在往该方向还能走的时候,继续往该方向走~
dy+=add[i][];
} }
f++;
}
return false;
} int main()
{
while(scanf("%d%d",&n,&m),n,m)
{
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&a[i][j]);
int k;
scanf("%d",&k);
while(k--)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(a[x1][y1]== || a[x2][y2]== || a[x1][y1]!=a[x2][y2]) {printf("NO\n");continue;}
if(bfs(x1,y1))
printf("YES\n");
else
printf("NO\n");
}
}
return ;
}

//memory:8308KB   time:3562ms

C.HDU 1166   敌兵布阵

其实......哎这道题做过╮(╯▽╰)╭......链接→_→

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int MAX=;
int a[MAX<<]; void build(int l,int r,int x)
{
if(l==r)
{
scanf("%d",&a[x]);
return;
}
int mid=(l+r)>>;
build(l,mid,x<<);
build(mid+,r,x<<|);
a[x]=a[x<<]+a[x<<|];
} void update(int p,int w,int l,int r,int x)
{
if(l==r)
{
a[x]+=w;
return;
}
int mid=(l+r)>>;
if(p<=mid) update(p,w,l,mid,x<<);
else
update(p,w,mid+,r,x<<|);
a[x]=a[x<<]+a[x<<|];
} int query(int le,int ri,int l,int r,int x)
{
if(le<=l && ri>=r)
return a[x];
int mid=(l+r)>>,re=;
if(le<=mid) re+=query(le,ri,l,mid,x<<);
if(ri>mid) re+=query(le,ri,mid+,r,x<<|);
return re;
} int main()
{
int t,n,cas=;
char str[];
scanf("%d",&t);
while(t--)
{
printf("Case %d:\n",++cas);
scanf("%d",&n);
build(,n,);
while()
{
scanf("%s",str);
if(str[]=='E') break;
int a,b;
scanf("%d%d",&a,&b);
if(str[]=='Q') printf("%d\n",query(a,b,,n,));
else
if(str[]=='S') update(a,-b,,n,);
else
update(a,b,,n,);
}
}
return ;
}

//memory:768KB  time:218ms

D.HDU 2602   Bone Collector

很水~DP

代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int w[],v[],f[]; int main()
{
int t,N,V,i,j;
scanf("%d",&t);
while(t--)
{
memset(f,,sizeof(f));
memset(w,,sizeof(w));
memset(v,,sizeof(v));
scanf("%d%d",&N,&V);
for(i=;i<=N;i++)
scanf("%d",&v[i]);
for(i=;i<=N;i++)
scanf("%d",&w[i]);
for(i=;i<=N;i++)
for(j=V;j>=w[i];j--)
{
int temp=f[j-w[i]]+v[i];
f[j]=max(f[j],temp);
}
printf("%d\n",f[V]);
}
return ;
}

//memory:428KB  time:15ms

E.HDU 2059   龟兔赛跑

DP

代码:

 #include <stdio.h>
#include <iostream>
#include <float.h>
using namespace std; #define MAX 110
int a[MAX];
double dp[MAX]; int main()
{
int l,n,c,t,vr,v1,v2;
while(~scanf("%d%d%d%d%d%d%d",&l,&n,&c,&t,&vr,&v1,&v2))
{
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
a[]=;
dp[]=0.0;
a[n+]=l;
for(int i=;i<=n+;i++)
{
dp[i]=DBL_MAX;
for(int j=;j<i;j++)
{
double len=1.0*(a[i]-a[j]);
double temp=(len>=c)?((c*1.0)/v1+(len-c)*1.0/v2):((len*1.0)/v1);
if(j) temp+=t;
dp[i]=min(dp[i],dp[j]+temp);
}
}
double rabit_time=(l*1.0)/vr;
if(dp[n+]>rabit_time)
printf("Good job,rabbit!\n");
else
printf("What a pity rabbit!\n");
}
return ;
}

//memory:284KB  time:15ms

8-11-Exercise的更多相关文章

  1. MIT 6.828 JOS学习笔记11 Exercise 1.8

    Exercise 1.8       我们丢弃了一小部分代码---即当我们在printf中指定输出"%o"格式的字符串,即八进制格式的代码.尝试去完成这部分程序. 解答: 在这个练 ...

  2. shodan 文档学习笔记

    Table of Contents 1. Introduction 1.1. All About the Data 1.2. Data Collection 1.3. SSL in Depth 1.3 ...

  3. 地区sql

    /*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : lo ...

  4. 《MIT 6.828 Lab 1 Exercise 11》实验报告

    本实验的网站链接:MIT 6.828 Lab 1 Exercise 11. 题目 The above exercise should give you the information you need ...

  5. BEC listen and translation exercise 11

    When you are in any contest you should work as if there were — to the very last minute — a chance to ...

  6. C - The C Answer (2nd Edition) - Exercise 1-1

    /* Run the "hello, world" program on your system. Experiment with leaving out parts of the ...

  7. MIT 6.828 JOS学习笔记5. Exercise 1.3

    Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...

  8. python第二天基础1-1

    一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. if 1==1: name = 'wupeiqi' print name 二.三元运算 result = 值1  ...

  9. Stanford coursera Andrew Ng 机器学习课程编程作业(Exercise 1)

    Exercise 1:Linear Regression---实现一个线性回归 在本次练习中,需要实现一个单变量的线性回归.假设有一组历史数据<城市人口,开店利润>,现需要预测在哪个城市中 ...

  10. Think Python - Chapter 11 - Dictionaries

    Dictionaries A dictionary is like a list, but more general. In a list, the indices have to be intege ...

随机推荐

  1. 数组-去重、排序方法、json排序

    1.数组去重 /*方法一: 1,'1' 会被认为是相同的; 所有hash对象,如:{x;1},{y:1}会被认为是相同的 //10ms */ Array.prototype.unique=functi ...

  2. 列表字体css

    white-space: nowrap; text-overflow: ellipsis; -o-text-overflow: ellipsis; overflow: hidden;

  3. tabbar - 取消系统渲染

    /**  1. 取消自动渲染 - 图片***/ viewCon1.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_home_ ...

  4. Cocoa Touch 框架

    Cocoa Touch包括: (1)Core Animation: 通过Core Animation,可以通过一个基于独立图层的简单的编程模型来创建丰富的用户体验. (2)Core Audio: Co ...

  5. 定位 - CoreLocation - INTULocationManager

    https://github.com/intuit/LocationManager #import "ViewController.h" #import "INTULoc ...

  6. 第 2 章 代理模式【Proxy Pattern】

    第 2 章 代理模式[Proxy Pattern] 以下内容出自:24种设计模式介绍与6大设计原则.pdf 什么是代理模式呢?我很忙,忙的没空理你,那你要找我呢就先找我的代理人吧,那代理人总要知道被代 ...

  7. using namespace std

    using namespace std std 是一个命名空间..不同的命名空间可以有相同的类名被定义 ..using namespace std;就是指明下面的程序使用std,如果不用这句指明的话就 ...

  8. QLGame 2d Engine 搭建2d游戏原理

    大家好,2d引擎基于opengl(es) 3d技术,是因为这样比之前的ddraw有很多好处! 1.坐标采用浮点数,可以进行曲线移动 2.如果在ddraw的对图片进行缩放和旋转的时候,是基于点像素的操作 ...

  9. Android 给ListView设置Adapter

    Adapter: class MyAdapter extends BaseAdapter { private List<Person> personList; public MyAdapt ...

  10. 【BZOJ 1319】 Sgu261Discrete Rootsv (原根+BSGS+EXGCD)

    1319: Sgu261Discrete Roots Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 389  Solved: 172 Descriptio ...