Kickdown

时间限制: 1000ms 内存限制: 65536KB

问题描述
A research laboratory of a world-leading automobile company has received an order to create a special transmission mechanism, which allows for incredibly efficient kickdown — an operation of switching to lower gear. After several months of research engineers found that the most efficient solution requires special gears with teeth and cavities placed non-uniformly. They calculated the optimal flanks of the gears. Now they want to perform some experiments to prove their findings.The first phase of the experiment is done with planar toothed sections, not round-shaped gears. A section of length n consists of n units. The unit is either a cavity of height h or a tooth of height 2h. Two sections are required for the experiment: one to emulate master gear (with teeth at the bottom) and one for the driven gear (with teeth at the top).

There is a long stripe of width 3h in the laboratory and its length is enough for cutting two engaged sections together. The sections are irregular but they may still be put together if shifted along each other.

The stripe is made of an expensive alloy, so the engineers want to use as little of it as possible. You need to find the minimal length of the stripe which is enough for cutting both sections simultaneously.

输入描述
There are two lines in the input file, each contains a string to describe a section. The first line describes master section (teeth at the bottom) and the second line describes driven section (teeth at the top). Each character in a string represents one section unit — 1 for a cavity and 2 for a tooth. The sections can not be flipped or rotated.Each string is non-empty and its length does not exceed 100.
输出描述
Write a single integer number to the output file — the minimal length of the stripe required to cut off given sections.
样例输入
sample input #1
2112112112
2212112sample input #2
12121212
21212121sample input #3
2211221122
21212

样例输出
sample output #1
10sample output #2
8sample output #3
15

来源
Northeastern Europe 2006
提示
注意:上面只是给出三个例子。 需要注意 input 中的“ There are two lines in the input file,...” 只有一组测试数据。不要输入“sample input #1”等标识符 和输出 “sample output #1”等标识符。

问题分析:

这个问题和《UVA1588 UVALive3712 POJ3158 Kickdown》是同一个问题,代码拿过来用就AC了。

程序说明:

参见参考链接。

参考链接:UVA1588 UVALive3712 POJ3158 Kickdown

题记:

程序做多了,不定哪天遇见似曾相识的。

AC的C++程序如下:

/* UVA1588 UVALive3712 POJ3158 Kickdown */  #include <stdio.h>
#include <string.h>  #define MIN(x, y) (((x)>(y))?(y):(x))  #define MAXN 100  char s[MAXN], t[MAXN];  int main(void)
{  int slen, tlen, ans1, ans2, i, j;  while(scanf("%s", s) != EOF) {  scanf("%s", t);  slen = strlen(s);  tlen = strlen(t);  /* s left, t right */  for(i=0; i<slen; i++) {  for(j=0; j<tlen && i+j<slen; j++) {  if(s[i+j] == '2' && t[j] == '2')  break;  }  if(j == tlen || i+j == slen)  break;  }  ans1 = i + tlen;  if(ans1 < slen)  ans1 = slen;  /* t left, s right */  for(j=0; j<tlen; j++) {  for(i=0; i<slen && j+i<tlen; i++) {  if(t[j+i] == '2' && s[i] == '2')  break;  }  if(i == slen || j+i == tlen)  break;  }  ans2 = j + slen;  if(ans2 < tlen)  ans2 = tlen;  printf("%d\n", MIN(ans1, ans2));  }  return 0;
} 

NUC1178 Kickdown【水题】相关推荐

  1. 水题/poj 1852 Ants

    1 /* 2 PROBLEM:poj1852 3 AUTHER:Nicole 4 MEMO:水题 5 */ 6 #include<cstdio> 7 using namespace std ...

  2. HDU2673-shǎ崽(水题)

    如果不能够直接秒杀的题,就不算水题.又应证了那句话,有时候,如果在水题上卡住,那么此题对于你来说,也就不算是水题了额~~ 刚睡醒,迷迷糊糊. 题目的意思很简单,求一个最大的,再求一个最小的.几乎是什么 ...

  3. 图论刷水题记录(二)(最短路-----SPFA算法)

    继第一篇的后续,又来刷水题了,写的是SPFA算法,这个算法的复杂度比较玄学,感觉能不用就不用了,但是他的好处就是可以判断负圈. 3月26日: 1.POJ 1847 Tram 题意:在一个交通网络上有N ...

  4. 图论刷水题记录(一)(最短路-----dijkstra算法)

    最近实在不知道干些什么,感觉自己除了水题什么都不会做,算了去刷一刷图论的水题吧本来想合起来一起发,想了想太长的话以后看起来也不方便,题目所以今天晚上就先发了dij部分,由上到下由易变难. 1.POJ ...

  5. hdu 2041:超级楼梯(水题,递归)

    超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  6. HDU2568 前进【水题】

    前进 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  7. CF Round #426 (Div. 2) The Useless Toy 思维 水题

    题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...

  8. NUC1312 Sum【水题+数学题】

    Sum 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 认为自然数是从1-N.将每个数和+或-联系起来,然后计算这个表达式的值我们得到一个和S.这个问题 ...

  9. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

  10. poj1564 Sum It Up dfs水题

    题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...

最新文章

  1. 013_JavaScript函数
  2. nginx rewrite规则和参考
  3. python非阻塞输入_python_非阻塞套接字及I/O流
  4. Angular Injector.create的工作原理
  5. java数组中的内存特征
  6. Codeforces 576D. Flights for Regular Customers(倍增floyd+bitset)
  7. ASP.Net Web API 的参数绑定[翻译]
  8. iOS开发UI篇—控制器的创建
  9. 感知器、logistic与svm 区别与联系
  10. vim如何删除^M字符
  11. Java解析HTML之NekoHTML
  12. 数据挖掘—网格搜索2
  13. 软件安装及软件包管理
  14. grubbs准则 matlab_MATLAB-格拉布斯准则(MATLAB-Grubbs criterion)_0
  15. 计算机工程与工艺截稿,中国计算机学会第二十届计算机工程与工艺学术年会
  16. 17、文件IO详解及实例
  17. 数据库load data命令批量插入txt文件的数据
  18. FFMPEG filter使用实例(实现视频缩放,裁剪,水印等)
  19. производство в смоленске кирпича
  20. CTF---Web---SQL注入---10---get传参的删减

热门文章

  1. Kubernetes支持有状态服务的部署
  2. mysql_fetch_array详解
  3. C#多线程学习(三) 生产者和消费者 1——解决线程间冲突的关键
  4. 【数据结构的魅力】002.单向、双向链表栈和队列递归
  5. tomcat的服务器目录在哪个文件夹,Tomcat目录结构详细介绍
  6. js接收php 回调,JS callback回调函数的使用(附代码)
  7. python财务管理
  8. Pytorch——可视化不同的优化器效果
  9. Linux C/C++开发环境搭建指针
  10. C语言之测试程序运行时间