uva1588kickdown
题目要求简述:给定长度分别为n1,n2(n1,n2<=100)且每列的高度只为1或者2的长条。需要将他们放入一个高度为3的容器,问能够容纳它们的最短容器长度。
思路就是固定一个字符串a,字符串b移动,再固定b,让a移动,取二者长度最小值。
之前写的函数有问题,wrong answer错误了很多遍,调试的时候学习了重定向,参考了一篇博客ac的。
#include<fstream>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define max 110
using namespace std; int min(const int &i, const int &j) {
return i<j ? i : j;
} int offset(char *s1, char *s2, int &ls1, int &ls2) {
int sum = ls1 + ls2, f, l = ls1 + ls2, minn = min(ls1, ls2);
bool flag;
for (int i = ;i < ls1;i++) {
flag = true;f = min(minn, ls1 - i);
for (int j = ;j < f;j++) {
if ((s1[i + j] == '') && (s2[j] == '')) {
flag = false;
break;
}
}
if (flag&&l > sum - f) {
l = sum - f;
}
}
return l;
} int main()
{
int offset(char *s1, char *s2, int &ls1, int &ls2);
char str1[max],str2[max];
int l1,l2;
/*ifstream fin("G:\\algorithm\\uva\\input\\1588in.txt");
ofstream fout("G:\\algorithm\\uva\\output\\result.txt");
streambuf *cinbackup;
streambuf *coutbackup;
coutbackup = cout.rdbuf(fout.rdbuf());
cinbackup = cin.rdbuf(fin.rdbuf()); */
while (cin >> str1 >> str2) {
l1 = strlen(str1);
l2 = strlen(str2);
int res1 = offset(str1,str2,l1,l2);
int res2 = offset(str2,str1,l2,l1);
cout << min(res1,res2) << endl;
memset(str1, , sizeof(str1));
memset(str2, , sizeof(str2));
}
return ;
}
uva1588kickdown的更多相关文章
- UVA1588-Kickdown
2018-10-30-18:27:03 原题链接 题目描述: 给出两个长度分别为n1,n2且每列高度只为1或2的长条,需要将它们放入一个高度为3的容器,求出能够容纳他们的最短容器长度. 本题思路: 模 ...
随机推荐
- win10突然不能使用usb大容量存储设备(移动硬盘)的解决方法
昨天开始使用usb硬盘,发现一块无法识别,一块识别好了以后不能打开. 可能是之前一次系统更新有bug,但是一直也没有用移动硬盘,所以没有发现. 开始尝试各种方案,已经尝试过并且无效的有以下几个: 1, ...
- Spring+SpringMVC+Mybatis大整合(SpringMVC采用REST风格、mybatis采用Mapper代理)
整体目录结构: 其中包下全部是采用mybatis自动生成工具生成. mybatis自动生成文件 <?xml version="1.0" encoding="UTF- ...
- Android-Lopper类的介绍(Handler背后的类)
转载来自:http://www.open-open.com/lib/view/open1325668588515.html Android中的Looper类,是用来封装消息循环和消息队列的一个类,用于 ...
- 集群 & 负载均衡
集群(Cluster) 指一组计算机系统构成一个松耦合的多处理器系统,它们之间通过网络实现进程间的通信,实现分布式计算.在客户端看来就像是只有一个服务器.集群可以利用多个计算机进行并行计算从而获得很高 ...
- 041. asp.net中内容页访问母版页中的控件
母版页运行机制: 用户通过输入内容也的URL来请求某个页面, 获取该页面后, 读取@Page指令, 如果该指令引用了一个母版页, 则也读取该母版页, 如果也是第一次请求这两个页面, 则母版页和被请求的 ...
- 获取ICommand的图片
BarButtonItem item = (BarButtonItem)e.Item; System.IntPtr _Handle = (System.IntPtr)(cmd as ICommand) ...
- .NET的ExcelOperate
using System; using System.Web; using Excel = Microsoft.Office.Interop.Excel; namespace Comm { /// & ...
- access生成sql脚本,通过VBA调用ADOX
access生成sql脚本,通过VBA调用ADOX. 使用 MS Access 2016 的VBA,读取mdb文件中的所有表结构(数据类型/长度/精度等),生成对应的SQL create table语 ...
- Turn off Debug Logging in Quartz .Net
Quartz.net uses Common.Logging, so something like this in your App.config/Web.config: <configSect ...
- Nginx安装、配置文档
Nginx介绍 nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开发 ...