spoj 247
不管行列 总是先切割切割费用大的 代码比较烂 ......
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
bool cmp(int a, int b)
{
return a > b;
}
int a[1010],b[1010];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int m,n;
scanf("%d%d",&m,&n);
for(int i = 0; i < m-1; i++)
{
scanf("%d",&a[i]);
}
for(int i = 0; i < n-1; i++)
{
scanf("%d",&b[i]);
}
sort(a, a+m-1, cmp);
sort(b, b+n-1, cmp);
int sum = 0;
int p,q;
p = q = 0;
while(p != m-1 || q != n-1)
{
if(p != m-1 && q != n-1 && a[p] >= b[q])
{
sum += a[p];
for(int j = q; j < n-1; j++)
{
sum += b[j];
}
p++;
}
else if(p != m-1 && q != n-1 && a[p] < b[q])
{
sum += b[q];
for(int j = p; j < m-1; j++)
{
sum += a[j];
}
q++;
}
else if(p == m-1)
{
for(int j = q; j < n-1; j++)
{
sum += b[j];
}
q = n-1;
}
else
{
for(int j = p; j < m-1; j++)
{
sum += a[j];
}
p = m-1;
}
}
printf("%d\n",sum);
}
return 0;
}
spoj 247的更多相关文章
- SPOJ 247 chocolate (CHOCLO)
题目http://www.spoj.com/problems/CHOCOLA/ 把一整块巧克力分成一个一个单元,掰断每一横行有个代价值,掰断每个纵行也有个代价值,要你求最后的总代价值最小 这个题目放在 ...
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- 【填坑向】spoj COT/bzoj2588 Count on a tree
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
- SPOJ bsubstr
题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...
- 【SPOJ 7258】Lexicographical Substring Search
http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...
- 【SPOJ 1812】Longest Common Substring II
http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...
- 【SPOJ 8222】Substrings
http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求 ...
随机推荐
- 使用SoapUI 测试 Web Service
一.官方定义 soapUI是一个开源测试工具,通过soap/http来检查.调用.实现Web Service的功能/负载/符合性测试.该工具既可作为一个单独的测试软件使用,也可利用插件集成到Eclip ...
- Swift构造器(Initializer)与析构器(Deinitializer)
为了初始化结构体和类等类型的实例属性. 默认构造器 struct Fahrenheit { var temperature: Doubleinit(){ temperature = 32.0 } } ...
- Swift方法
Swift 中的方法是与特定类型(类和结构体)相关的函 数. 实例方法 隶属于某个特定类型(类或结构体)实例函数. class Counter{ var count = 0 funcincrement ...
- JSTL截取字符串
引入头文件支持<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> &l ...
- C++与Lua交互(二)
上一篇我们搭建好了整个的项目环境,现在,我们一起探索一下如何将lua寄宿到C++中. 宿主的实现 我们在LuaWithCPPTest项目下,查看Source.cpp代码如下: #include < ...
- Headfirst设计模式的C++实现——复合模式
observer.h #ifndef _OBSERVER_H_ #define _OBSERVER_H_ #include <string> class Observer { public ...
- struts2.3.15.1 中jsp:include与jsp:forward的用法
首先配置好struts2的过滤器:web.xml中的配置 <filter> <filter-name>struts-prepare</filter-name> &l ...
- 怎么在spring官网上下载spring的jar包, 源代码和文档?
现在 http://repo.spring.io/release/org/springframework/spring/第一种,简单粗暴直接 1 http://repo.springsource.or ...
- 使用XFire+Spring构建Web Service
XFire是与Axis 2并列的新一代Web Service框架,通过提供简单的API支持Web Service各项标准协议,帮助你方便快速地开发Web Service应用. 相 对于Axis来说,目 ...
- 解决FPDF报错:FPDF error: Not a JPEG file / FPDF error: Not a PNG file
最近有个项目需要用到FPDF,但是输出的时候报错: FPDF error: Not a JPEG file: http://***/data/attachment/forum/201603/19/10 ...