poj 3158kickdown
我是来吐槽poj的!!!
第一次做poj,被题目中的输入输出格式打败了 ,醉了醉了
Description
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.
Input
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.
Output
Write a single integer number to the output file — the minimal length of the stripe required to cut off given sections.
Sample Input
sample input #1
2112112112
2212112 sample input #2
12121212
21212121
sample input #3 2211221122 21212
Sample Output
sample output #1
10 sample output #2
8 sample output #3
15 我一直以为输入输出中的”sample output #3“这玩意也要输入输出的就试了一下午!!
明明答案死活都对!!!简直被自己蠢哭了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
这是我第一次的代码,本来一次过的题!!!我的一下午!!!!!!!!!!!!!!
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int f(string a,string b)
{
int n1=a.length(),n2=b.length(),t=-,j=,k=;
for(int i=;i<n1;i++){
if((a[i]+b[j]-''*)<){
k=;
j++;
if(t==-)t=i;
}
else{
if(i==n1-&&j==)return n1+n2;
if(k==&&t!=-){
i=t;
t=-;
}
j=;
}
if(j==n2)return n1;
}
return t+n2;
}
int main()
{
string o1,o2,o3,a,b;
int k=,t;
while(cin>>o1>>o2>>o3){
cin>>a;
cin>>b;
int t1=t=f(b,a),t2=f(a,b);
if(t1>t2)t=t2;
printf("sample output #%d\n%d\n\n",k++,t);
}
return ;
}
这简直绝望了
各种改,试了无数组数据,真的绝望了!!!!!!!!!!!!!!
再看了AC代码后,真的要哭了..............
改完AC..............
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
char a[],b[];
int f(char* a,char* b)
{
int n1=strlen(a),n2=strlen(b),t=-,j=,k=;
for(int i=;i<n1;i++){
if((a[i]+b[j]-''*)<){
k=;
j++;
if(t==-)t=i;
}
else{
if(i==n1-&&j==)return n1+n2;
if(k==&&t!=-){
i=t;
t=-;
}
j=;
}
if(j==n2)return n1;
}
return t+n2;
}
int main()
{
int t;
while(cin>>a>>b){
int t1=t=f(b,a),t2=f(a,b);
if(t1>t2)t=t2;
printf("%d\n",t);
}
return ;
}
题目要求两块木头不能旋转,若可以旋转,将一个字符串倒过来即可
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
//char d[110]; //旋转
char a[],b[];
int f(char* a,char* b)
{
int n1=strlen(a),n2=strlen(b),t=-,j=,k=;
for(int i=;i<n1;i++){
//printf("a[%d]+b[%d]=%c+%c=%d\n",i,j,a[i],b[j],a[i]+b[j]-'0'*2);
if((a[i]+b[j]-''*)<){
k=;
j++;
//cout<<"i"<<i<<endl;
if(t==-)t=i;
}
else{
if(i==n1-&&j==)return n1+n2;
if(k==&&t!=-){
i=t;
//cout<<"i"<<i<<endl;
t=-;
}
j=;
}
if(j==n2)return n1;
}
return t+n2;
}
/*char* g(string a) // 旋转
{
int n=a.length();
for(int i=0;i<n;i++)d[i]=a[n-1-i];
d[n]='\0';
return d;
}*/
int main()
{
int k=,t;
while(cin>>a>>b){
int t1=t=f(b,a),t2=f(a,b);//,n=a.length(); //旋转
if(t1>t2)t=t2;
/*string c=g(a); // 旋转
t1=f(c,b),t2=f(b,c);
if(t1>t2)t1=t2;
if(t>t1)t=t1;*/
printf("sample output #%d\n%d\n\n",k++,t);
}
return ;
}
poj 3158kickdown的更多相关文章
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- mysql-5.7.12-winx64.zip Windows (x86, 64-bit), ZIP Archive版免安装配置
1.下载免安装版压缩包 下载地址:http://dev.mysql.com/downloads/mysql/ 选择符合你的操作系统的版本,点击download进入下载页面 不用注册也可以点击下载连接进 ...
- Keil C减小代码编译量大小的方法(gai)
keil-C减小代码编译大小的方法整理 方法一:(通过优化代码减小) 1.1少做乘除运算,使用左/右移位来实现乘除 Eg ,普通:a = 0x80*4: 优化:a = 0x80<<2: 1 ...
- Ajax中send方法参数的使用
一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null. 例如 : var url = " ...
- log4j配置文件及nutch中的日志配置
使用slf4j作为日志系统时,由于slf4j只是一个接口,它需要一个具体实现来执行. 具体参考http://blog.csdn.net/jediael_lu/article/details/43854 ...
- AsEnumrable和AsQueryable的区别
http://www.cnblogs.com/jianglan/archive/2011/08/11/2135023.html 在写LINQ语句的时候,往往会看到.AsEnumerable() 和 . ...
- TypeError: not enough arguments for format string
到一个问题,表示100% 的时候,出现这个问题. 因为python语法会认为是你需要转移符,这个时候你可以选择100%% 来表示
- linux crond服务
linux crond服务 linux crond服务简介:定时执行系统命令 查看crond服务状态:[root@www ~]# /sbin/service crond status 启动.停止.重启 ...
- DDP和DDU什么区别
DU/DDP 就是A发货给国外B,B只要呆在家里看电视,货会自动送上门,当中的所有运输清关等事情都是由A来负责(A可以委托货代来负责),区别就是DDU是不包括税金的,也就是货值的百分之多少,税金会在B ...
- keil C 应注意的几个问题
我们使用Keil C调试某系统时积累的一些经验 1.在Windows2000下面,我们可以把字体设置为Courier,这样就可以显示正常.2.当使用有片外内存的MCU(如W77E58,它有1K片外内存 ...
- heritrix 3.2.0 -- 环境搭建
heritrix作为一个比较经典的开源爬虫,写这篇文章目的是因为,3.X之后的heritrix的介绍以及配置的文章比较少了. heritrix 3.x 以后使用maven 2配置jar包引用,但是总是 ...