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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- hdu 2438Turn the corner 三分
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 2143 数组合并 二分
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- hdu 1263 水果
Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样J ...
- 简单的LRU Cache设计与实现
要求: 设计并实现一个LRU缓存的数据结构,支持get和set操作 get(key):若缓存中存在key,返回对应的value,否则返回-1 set(key,value):若缓存中存在key,替换其v ...
- C#中弹出新窗口
1.在主窗体程序中定义对应别的窗体的对象 Form_a_class form1 = Form_a_class test_delegate(); 2.调用显示 form1.ShowDialog();
- Android开发笔记之: 数据存储方式详解
无论是神马平台,神马开发环境,神马软件程序,数据都是核心.对于开发平台来讲,如果对数据的存储有良好的支持,那么对应用程序的开发将会有很大的促进作用.总体的来讲,数据存储方式有三种:一个是文件,一个是数 ...
- 锋利jQuery 学习整理之 第六章 jQuery 与Ajax 的应用
1.Ajax 的XMLHttpRequest 对象 XMLHttpRequest 是Ajax 的核心,它是Ajax 实现的关键---发送异步请求.接受响应及执行回调都是通过它来完成的.XMLHttpR ...
- 帝国cms7.0整合百度编辑器ueditor教程
帝国cms7.0整合百度编辑器ueditor教程开始 1.根据自己使用的帝国cms版本编码下载对应的ueditor版本 下载地址 http://ueditor.baidu.com/website/do ...
- Python基础第五天
双层装饰器 字符串格式化 Python字符串格式有2种方式:百分号方式.format方式:建议使用format方式 1.百分号方式 格式:%[(name)][flags][width].[precis ...