链接:第四次小练

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. couchDB入门

    无意翻到一本新书<CouchDB权威指南> 发现这就是传说中的NoSQL,看排第一的是mangodb,redis有些人说是,有些人说不是. CouchDB的开发很天才,直接可以通过java ...

  2. 测试网站是共享还是独立ip

    查看是共享还是独立:http://www.yougetsignal.com/tools/web-sites-on-web-server/ 站长工具:http://tool.webmasterhome. ...

  3. jquery 缓冲加载图片插件 jquery.lazyload

    第一:加入jquery 第二:加入jquery.lazy.load.js文件 第三:在网页中加<script> $(document).ready(function(){ $(" ...

  4. Mac苹果电脑加密视频播放器使用教程

    1.   下载文件 https://pan.baidu.com/s/1slhFYuL 2.    操作流程 温馨提示 播放时,请务必保证播放设备联网(原因:用户名权限验证需要网络,播放后10秒即可关闭 ...

  5. scp命令使用

    从 本地 复制到 远程 scp /home/daisy/full.tar.gz root@172.19.2.75:/home/root (然后会提示你输入另外那台172.19.2.75主机的root用 ...

  6. android 布局权重问题(转载)

    //权重和父容器orientation有关 horizontal 指水平方向权重  android:layout_width vertical  指垂直方向权重   android:layout_he ...

  7. 如何在django的filter中传递字符串变量作为查询条件(动态改变查询条件)

    一般来说在需要查询数据的时候都是以下形式 ret=Articles.objects.filter(id=1) 然而如果要动态的改变查询的条件怎么办呢? 如下代码 def getModelResult( ...

  8. bzoj 4031: [HEOI2015]小Z的房间 轮廓线dp

    4031: [HEOI2015]小Z的房间 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 98  Solved: 29[Submit][Status] ...

  9. bzoj 3781: 小B的询问 分块

    3781: 小B的询问 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 196  Solved: 135[Submit][Status] Descrip ...

  10. BZOJ 1231: [Usaco2008 Nov]mixup2 混乱的奶牛

    Description 混乱的奶牛 [Don Piele, 2007] Farmer John的N(4 <= N <= 16)头奶牛中的每一头都有一个唯一的编号S_i (1 <= S ...