8-11-Exercise
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的更多相关文章
- MIT 6.828 JOS学习笔记11 Exercise 1.8
Exercise 1.8 我们丢弃了一小部分代码---即当我们在printf中指定输出"%o"格式的字符串,即八进制格式的代码.尝试去完成这部分程序. 解答: 在这个练 ...
- shodan 文档学习笔记
Table of Contents 1. Introduction 1.1. All About the Data 1.2. Data Collection 1.3. SSL in Depth 1.3 ...
- 地区sql
/*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : lo ...
- 《MIT 6.828 Lab 1 Exercise 11》实验报告
本实验的网站链接:MIT 6.828 Lab 1 Exercise 11. 题目 The above exercise should give you the information you need ...
- 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 ...
- C - The C Answer (2nd Edition) - Exercise 1-1
/* Run the "hello, world" program on your system. Experiment with leaving out parts of the ...
- MIT 6.828 JOS学习笔记5. Exercise 1.3
Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...
- python第二天基础1-1
一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. if 1==1: name = 'wupeiqi' print name 二.三元运算 result = 值1 ...
- Stanford coursera Andrew Ng 机器学习课程编程作业(Exercise 1)
Exercise 1:Linear Regression---实现一个线性回归 在本次练习中,需要实现一个单变量的线性回归.假设有一组历史数据<城市人口,开店利润>,现需要预测在哪个城市中 ...
- Think Python - Chapter 11 - Dictionaries
Dictionaries A dictionary is like a list, but more general. In a list, the indices have to be intege ...
随机推荐
- linux根目录详解
ubuntu 文件说明:http://tech.ccidnet.com/art/302/20080118/1347213_1.html/ 根目录 | |-boot/ 启动文件.所有与系统启动有关的 ...
- CSS 常用命名
在前端开发中,规范使用 DIV+CSS 命名,可以增强团队合作提高开发效率,有利于页面后期的维护和优化. 1.页面结构 wrap:外套.包裹,用于最外层. wrapper:外套,用于页面外围控制整体布 ...
- 禁止选择文本和禁用右键 v1.0
var zhonghao={ //绑定事件 myAddEvent: function(obj, sEvent, fn){if(obj.attachEvent){obj.attachEvent('on' ...
- 此文件时入口文件index.php
此文件时入口文件index.php <?php //定义一下ThinkPHP框架存放的路径 define('THINK_PATH','./ThinkPHP/'); //定义当前的项目的名称,此处 ...
- PHP全局变量
1.global 关键字 2.$GLOBALS 3.使用静态变量
- UIImage拉伸显示
下面张图片,是设计来做按钮背景的: button.png,尺寸为:24x60 现在我们把它用作为按钮背景,按钮尺寸是150x50,以下是没有经过技术性拉伸处理的情况: // 得到view的尺寸 ...
- SQL Join PK ChinaJoy
P PK
- Memcached(二)Memcached Java API基础之MemcachedClient
1. 构造函数 public MemcachedClient(InetSocketAddress[] ia) throws IOException; public MemcachedClient(Li ...
- Log4j与common-logging
Log4j与common-logging 总网上搜了些Log4j与common-logging的介绍,记录下. 一.Log4j 1.简介 Log4j是Apache的一个开放源代码项目 使用Log4j ...
- [原博客] POJ 1740 A New Stone Game
题目链接题意:有n堆石子,两人轮流操作,每次每个人可以从一堆中拿走若干个扔掉(必须),并且可以从中拿走一些分到别的有石子的堆里(可选),当一个人不能拿时这个人输.给定状态,问是否先手必胜. 我们参考普 ...