我是来吐槽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的更多相关文章

  1. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  2. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  3. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  4. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  5. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  8. 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 ...

  9. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

随机推荐

  1. 重写String类,也有些区别,供参考

    头文件如下: #pragma once #include <string> #include <string.h> #include <stdlib.h> #inc ...

  2. jQuery输入框提示自动完成插件 autocomplete

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  3. 转载收藏之用 - 微信公众平台开发教程(六):了解MessageHandler

    上一篇<Senparc.Weixin.MP SDK 微信公众平台开发教程(五):使用Senparc.Weixin.MP SDK>我们讲述了如何使用Senparc.Weixin.MP SDK ...

  4. github在eclipse中的配置

    http://www.cnblogs.com/yejiurui/archive/2013/07/29/3223153.html http://blog.csdn.net/shehun1/article ...

  5. document.body.scrollTop vs document.documentElement.scrollTop && document.body.scrollHeight vs document.documentElement.scrollHeight

    FireFox下 document.body.scrollHeight || document.documentElement.scrollHeight;//等价 document.body.scro ...

  6. LeetCode_Palindrome Number

    Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...

  7. 在FMX中实现PostMessage的方法

    在FMX中实现PostMessage的方法 http://www.qdac.cc/?p=1090 2014-10-31 • Android.C++ Builder.Delphi.杂谈 • 4条评论 • ...

  8. Cocos2d-x程序Windows下VC中文乱码的解决(用MultiByteToWideChar进行转换,VC2010有非常厉害的execution_character_set)

    Cocos2d-x默认字符串常量编码都是UTF8的,而Windows中的VC默认都是跟系统相同,比如简体Windows是GB2312或者GBK.繁体就是BIG5编码.而我们大多数中国人用VC编译出来的 ...

  9. 购物车Demo,前端使用AngularJS,后端使用ASP.NET Web API(2)--前端,以及前后端Session

    原文:购物车Demo,前端使用AngularJS,后端使用ASP.NET Web API(2)--前端,以及前后端Session chsakell分享了前端使用AngularJS,后端使用ASP.NE ...

  10. UESTC_敢说就敢做 CDOJ 631

    敢说就敢做 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Sta ...