链接:第四次小练

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. JavaScript语言用10张图

    JavaScript 语言基础知识点总结,用图片树形结构说明.包括Windows对象.JavaScriptDOM基本操作.JavaScript变量.JavaScript数据类型.JavaScript运 ...

  2. 下载APP 2个二维码合并到一个二维码

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  3. 韩顺平_JAVA_视频教程_下载(打开迅雷,直接复制链接地址即可下载)

    ed2k://|file|韩顺平.循序渐进学.java.从入门到精通.第0讲-开山篇.avi|37021064|f4fb2fb3db938a642146ccc8f0935fed|h=ao2k3ep7p ...

  4. struts2简介

    MVC框架.不过有一点需要注意的是:struts2和struts2虽然名字很相似,但是在两者在代码编写风格上几乎是不一样的.那么既然有了struts1,为什么还要推出struts2.主要的原因是str ...

  5. 解决Android SDK Manager更新(一个更新Host的程序的原理实现和源码)

    <ignore_js_op>     同学遇到了更新Android SDK的问题,而且Goagent现在也无法用来更新.就想到了用替代Host的方法,添加可用的谷歌地址来实现更新.    ...

  6. java版 正文抽取 基于文字连接比

    package cn.tdt.crawl.jdbc; import java.util.regex.Matcher; import java.util.regex.Pattern; import or ...

  7. BZOJ 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富

    Description 最近,奶牛们热衷于把金币包在面粉里,然后把它们烤成馅饼.第i块馅饼中含有Ni(1<=Ni<=25)块金币,并且,这个数字被醒目地标记在馅饼表面. 奶牛们把所有烤好的 ...

  8. 限制sqlserver最大内存后无法连接-EXEC sp_configure max server memory

    在sql server 中设置了过小的 "max server memory"最大内存后,sqlserver可启动,但是无法连接. 网络上流行的"sqlserver 内存 ...

  9. php 文件下载 以及 file_exists找不到文件的解决方案

    链接:<a href="upload/file/download.php?filename=雨人工作室.doc" target="_blank" > ...

  10. 【Xamarin 跨平台机制原理剖析】

    原文:[Xamarin 跨平台机制原理剖析] [看了请推荐,推荐满100后,将发补丁地址] Xamarin项目从喊口号到现在,好几个年头了,在内地没有火起来,原因无非有三,1.授权费贵 2.贵 3.原 ...