Problem A.A Simple Problem

比赛时唯一做出来的一道题。

描述:

Time limit: 1 second
Memory limit: 256 megabytes
There's one row of buttons lying on onmylove's laptop keyboard, which are used to input the numbers,
just as shown in the picture:


onmylove used to input the numbers with his two specic ngers, one is on the left, the other is on the
right. In one unit time, onmylove's two ngers can both operate. For each nger, each operation can be
one of the following:
1.press on the button just under the nger.
2. move to the left button or the right button.
But there're still some points you should pay attention to:
1. at any time, the left nger should at the left side of the right nger.
2. in one unit of time, only one of these two ngers can press the button under it. Of course, the other
nger can move at this unit of time.
Now you are given a string which consists of only numbers, you are asked to calculate: if onmylove want
to input all these numbers, how many time does he need at least? At the every beginning, the left nger
is above the button \5" and the right nger is above the button \6".

Input
Multiple inputs. For each test case, there is one string at a line. It's promised there're only numbers in
the string and the length of it is not more than 100.

Output
For each test case, output one number at a line, which represents the least time you need.
Sample input and output

input:
434
56
57
47

output:
5
2
2
3

Problemsetter
onmylove

分析:这是一道DP题,根据时间划分阶段,状态d[t,i,j]表示第t秒,左手放在i,右手放在j可以敲出的最多字符数。根据题目规则,有9种转移方式,

用一个二维数组表示就是:dir[9][2] = {{0, -1}, {0, 1}, {-1, 0}, {-1, 1}, {-1, -1}, {1, 0}, {1, -1}, {1, 1}, {0, 0}}。

代码

1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <ctype.h>
5 #include <math.h>
6 #include <set>
7 #include <map>
8 #include <queue>
9 #include <vector>
10 #include <algorithm>
11  using namespace std;
12
13  #define NL1 201
14  #define NL2 21
15 #define EP 1e-10
16 #define MAX(x,y) ((x)>(y)?(x):(y))
17 #define MIN(x,y) ((x)<(y)?(x):(y))
18 #define LL long long
19
20 int d[NL2][NL2], d1[NL2][NL2];
21 int dir[9][2] = {{0, -1}, {0, 1}, {-1, 0}, {-1, 1}, {-1, -1}, {1, 0}, {1, -1}, {1, 1}, {0, 0}};
22 char ch[NL1];
23
24 int main() {
25 int i, j, k;
26 // freopen("in.txt", "r", stdin);
27 while (scanf("%s", ch+1) != EOF) {
28 int L = strlen(ch+1);
29 memset(d, -1, sizeof(d));
30 d[5][6] = 0;
31 int t=0;
32 bool suc = false;
33 while (1) {
34 t++;
35 memset(d1, -1, sizeof(d1));
36 for (i=1; i<=9; i++) {
37 for (j=i+1; j<=10; j++) {
38 if (d[i][j]>=0) {
39 for (k=0; k<9; k++) {
40 int i0 = i+dir[k][0];
41 int j0 = j+dir[k][1];
42 if (i0<j0 && i0>=1 && i0<=9 && j0>=2 && j0<=10) {
43 if (i == i0 && ch[d[i][j]+1] == i+'0') {
44 if (d1[i0][j0] == -1) {
45 d1[i0][j0] = d[i][j]+1;
46 }else {
47 d1[i0][j0] = MAX(d1[i0][j0], d[i][j]+1);
48 }
49 }
50 if (j==j0 && ch[d[i][j]+1] == ((j==10)?0:j)+'0') {
51 if (d1[i0][j0] == -1) {
52 d1[i0][j0] = d[i][j]+1;
53 }else {
54 d1[i0][j0] = MAX(d1[i0][j0], d[i][j]+1);
55 }
56 }
57 if (i!=i0 && j!=j0) {
58 if (d1[i0][j0] == -1) {
59 d1[i0][j0] = d[i][j];
60 }else {
61 d1[i0][j0] = MAX(d1[i0][j0], d[i][j]);
62 }
63 }
64 if (d1[i0][j0] == L) {
65 suc = true;
66 break;
67 }
68 }
69 }
70 if (suc) break;
71 }
72 if (suc) break;
73 }
74 if (suc) break;
75 }
76 for (i=0; i<=9; i++) {
77 for (j=i+1; j<=10; j++) {
78 d[i][j] = d1[i][j];
79 }
80 }
81 if (suc) break;
82 }
83 printf("%d\n", t);
84 }
85 return 0;
86 }
87

转载于:https://www.cnblogs.com/superbin/archive/2010/09/25/1834492.html

2010 ACM/ICPC Online-Contest-SCU[四川赛区网络预选赛]相关推荐

  1. 2018年 ACM/ICPC亚洲区域赛 青岛赛区现场赛 比赛总结

    首先祝贺自己收获了ACM生涯中的第二枚铜牌. 首先吐槽一下中石油: 周六早上来到中国石油大学,连个志愿者小姐姐都没看到.(但是看到了女装大佬).报完到之后发现教练少了一张午餐券(要不要这么粗心).为了 ...

  2. ACM-ICPC 2018沈阳赛区网络预选赛

    待更新 转载于:https://www.cnblogs.com/scott527407973/p/9614454.html

  3. 了解一下ACM/ICPC比赛时间

    2009 ACM/ICPC 中国大陆5个赛区具体日程(含网络选拔赛时间) 1. Harbin 哈尔滨赛区(哈尔滨工业大学) 网络选拔赛日期:2009年9月13日12:00-17:00 现场赛日期:20 ...

  4. 2014 ACM/ICPC 北京赛区网络赛解题报告汇总

    首页 算法竞赛» 信息聚合 ONLINE JUDGE 书刊杂志 BLOG» 新闻故事» 招聘信息» 投稿须知 2014 ACM/ICPC 北京赛区网络赛解题报告汇总 九月 21st, 2014 | P ...

  5. Samara SAU ACM ICPC Quarterfinal Qualification Contest 2012

    Samara SAU ACM ICPC Quarterfinal Qualification Contest 2012 D 题意 把一个数每次取走一个因子,直至1为止,取不同的因子算不同的方案,问有几 ...

  6. 2016 ACM / ICPC Asia dalian Regional Contest 题解(11 / 11)【每日亿题2021 / 2 / 17】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A .(2017 ACM ICPC dalian H)To begin or not to be ...

  7. 2011 ACM/ICPC 福州赛区网络赛解题报告

    第一次写网络赛的题解,福州赛区网络赛作为我第一年ACM最后一次网络赛酱油,画了一个很像逗号的句号.....好吧,还得为北京现场赛准备啊准备....... 这次酱油打的很犀利,貌似出第一题很快,之后节奏 ...

  8. PKU ACM/ICPC竞赛队最近八年比赛成绩

    PKU ACM/ICPC竞赛队最近八年比赛成绩 (不含预选赛前十名以外) 竞赛名称 年度 获奖名次 学生姓名 备 注 第29届ACM国际 大学生程序设计竞赛 亚洲区预选赛 2004 北京赛区第4名 饶 ...

  9. ACM / ICPC 在线OJ(Online judge)

    1. codeforces    codeforces (这个网站每天会有比赛,一起打CF吧!) http://codeforces.com/problemset 2.  topcoder:  htt ...

最新文章

  1. asp.net工程中aspx文件与codebehind文件的关联问题
  2. ISE中ChipScope软件使用
  3. 第十七课:js数据缓存系统的原理
  4. 理解ResNet结构与TensorFlow代码分析
  5. centos6.4 搭建knowlededgeroot-1.0.4知识库平台
  6. mysql-workbench连接数据库
  7. 电脑删除快捷键_可能是知乎最有用的 Windows 快捷键学习指南。
  8. 根因分析初探:一种报警聚类算法在业务系统的落地实施 1
  9. python增删改查mysql_python对数据库mysql的操作(增删改查)
  10. 鱼骨图分析法实际案例_会用“鱼骨图”的项目经理无难题
  11. JS将数字转换为中文
  12. 卷积神经网络之AlexNet
  13. 手机流量网络私有地址
  14. Spring框架学习总结(上)
  15. ucos 时钟节拍_uC/OS-III 时钟节拍,时间管理,时间片调度
  16. REW声学测试(五):测试所需设备
  17. Mysql删除数据什么情况下会释放空间
  18. PTA天梯赛L1-040 最佳情侣身高差(c语言实现)
  19. Jmockit对类静态方法mock
  20. MATLAB函数——premnmx

热门文章

  1. python 回溯法 子集树模板 系列 —— 3、0-1背包问题
  2. 汉语分词工具的研发-----
  3. spring mvc相关问题
  4. mysql 字符集和校对规则
  5. 利用组策略防止计算机访问共享资源
  6. HandlerInterceptor里@Autowired对象为空的解决方法
  7. 解读Raft(二 选举和日志复制)
  8. WCF服务创建与使用(双工模式)
  9. Nginx对某个文件夹或整个站点进行登录认证的方法
  10. 内存回收的一些基本方法