百度之星2014复赛 - 1001 - Find Numbers
先上题目:
Find Numbers
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 26 Accepted Submission(s): 20
Special Judge
下面2T行,每两行是一个询问。对于每两行:
第一行,n。
第二行,n个整数,a_0, a_1, ..., a_{n-1}。
数据范围:
1<=T<=20
1<=n<=2^15
0<=a_i<=10^9
Case #i:
第二行为结果:
如果不能选出这样的(n+1)/2个数,输出-1;
否则输出一行,用一个空格分隔的(n+1)/2个数b_0, b_1, ..., b_{(n+1)/2-1}。满足0<=b_i<n, b_i两两不同,且sum(a_{b_i})是(n+1)/2的倍数。如果有多解,输出任意一个。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <utility>
#define MAX 32770
#define LL long long
using namespace std; typedef pair<int,LL> pii; pii s[MAX];
int n,e;
LL f;
stack<int> st; bool dfs(int c){
if(!e){
if(f%((n+)/)==) return ;
return ;
}
for(int i=c;i<n;i++){
st.push(s[i].first);
f+=s[i].second;
e--;
if(dfs(i+)) return ;
st.pop();
f-=s[i].second;
e++;
}
return ;
} int main()
{
int t;
//freopen("data.txt","r",stdin);
scanf("%d",&t);
for(int z=;z<=t;z++){
scanf("%d",&n);
e = (n+)>>;
for(int i=;i<n;i++){
scanf("%I64d",&s[i].second);
s[i].first=i;
}
sort(s,s+n);
while(!st.empty()) st.pop();
f=;
printf("Case #%d:\n",z);
if(!dfs()) printf("-1");
else for(int i=;!st.empty();i++){
if(i) putchar(' ');
printf("%d",st.top());
st.pop();
}
putchar('\n');
}
return ;
}
1001
百度之星2014复赛 - 1001 - Find Numbers的更多相关文章
- 【百度之星2014~复赛 解题报告~正解】The Query on the Tree
声明 笔者最近意外的发现 笔者的个人网站http://tiankonguse.com/ 的很多文章被其它网站转载,但是转载时未声明文章来源或参考自 http://tiankonguse.com/ 网站 ...
- 【百度之星2014~复赛)解题报告】The Query on the Tree
声明 笔者最近意外的发现 笔者的个人网站http://tiankonguse.com/ 的很多文章被其它网站转载,但是转载时未声明文章来源或参考自 http://tiankonguse.com/ 网站 ...
- 百度之星2014复赛 - 1002 - The Query on the Tree
先上题目: The Query on the Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- 【百度之星2014~初赛(第二轮)解题报告】Chess
声明 笔者近期意外的发现 笔者的个人站点http://tiankonguse.com/ 的非常多文章被其他站点转载.可是转载时未声明文章来源或參考自 http://tiankonguse.com/ 站 ...
- 【百度之星2014~初赛(第二轮)解题报告】JZP Set
声明 笔者近期意外的发现 笔者的个人站点http://tiankonguse.com/ 的非常多文章被其他站点转载,可是转载时未声明文章来源或參考自 http://tiankonguse.com/ 站 ...
- 百度之星初赛2A 1001 ALL X(HDU 5690)
All X Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- [百度之星2014资格赛] Disk Schedule 报告
Disk Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- 百度之星2014初赛 - 1002 - Grids
先上题目: Grids Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 百度之星2014资格赛 1003 - Xor Sum
先上代码: Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)T ...
随机推荐
- hdu1150——最小点覆盖
As we all know, machine scheduling is a very classical problem in computer science and has been stud ...
- Cosine Similarity of Two Vectors
#include <iostream>#include <vector>#include <cmath>#include <numeric> templ ...
- Python入门 老司机带你上路
Phthon安装 https://www.python.org/download/releases/2.7.5/ 安装结束还没完,我们还差最后一步:设置环境变量.这是什么东西我暂时先不解释,大家照着做 ...
- (Go)07.Go语言中strings和strconv包示例代码详解02
1.strings使用 统计字符串出现次数 strings.Count(s string, substr string) int Count 用于计算字符串 substr 在字符串 s 中出现的非重叠 ...
- js getyear和getfullyear
getyear()函数如果今年是2015年会得到115,getfullyear()会得到完整的年份.
- WebService常用技术及术语
一.Web Service是什么? 1. 基于Web的服务:服务器端整出一些资源让客户端应用访问(获取数据) 2. 一个跨语言.跨平台的规范(抽象) 3. 多个跨平台.跨语言的应用间通信整合的方案(实 ...
- mvp 不错的链接
http://www.imooc.com/wenda/detail/216700 http://www.cnblogs.com/mybkn/archive/2012/04/12/2443676.htm ...
- vs2008 启动IE浏览器 出现DW20.exe占用大量cpu 服务器iis 异常调试
DW20.exe占用大量cpu 服务器iis运行出现异常想查一下故障原因,发现有好几个DW20.exe进程,每个占用20%左右的cpu,在任务管理器中将其终止后,它又自动运行起来了 查了一下DW20. ...
- 5.14JDBC
一.##JDBC 1. 概念:Java DataBase Connectivity Java 数据库连接, Java语言操作数据库. JDBC本质:其实是官方(sun公司)定义的一套操作所有关系型数 ...
- Jquery IE8兼容性
环境: jsp+jquery-1.11.1.min.js 问题描述: 使用$("#article标签id名").append(“xxxxxxxxx") ,chrome.f ...