A. Cards with Numbers
来源:互联网 发布:百龄洁牙粉 知乎 编辑:程序博客网 时间:2024/04/29 16:00
Petya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card with number i, as ai. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains the sequence of 2n positive integersa1, a2, ..., a2n (1 ≤ ai ≤ 5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.
If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer-1. But if the required partition exists, then print n pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.
320 30 10 30 20 10
4 21 56 3
11 2
-1
解题说明:此题就是给定一列数字,看能不能均分为两等份。可以先对数字进行排序,保证大小不同的数字出现偶数次,为了记录下标,用一个pair来保存比较方便。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;pair<int ,int > a[600100];int n,i;int main(){freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);cin>>n;for( i=1; i<=2*n; i++){cin>>a[i].first; a[i].second=i; }sort(a+1,a+n*2+1);for( i=1; i<=n*2; i+=2){if (a[i].first!=a[i+1].first){cout<<-1<<endl; return 0;}}for( i=1; i<=n*2; i+=2){cout<<a[i+1].second<<' '<<a[i].second<<endl;}}
- A. Cards with Numbers
- Cards with Numbers
- A. Cards
- No. 09 - Numbers with a Given Sum
- PAT-A 1023. Have Fun with Numbers
- pat a 1023 Have Fun with Numbers
- OCF, the OpenCard Framework is a standard Java framework for working with Smart Cards.
- 398A - Cards CF
- Codeforces 398 A. Cards
- CodeForces 398A Cards
- A. Vanya and Cards
- A. Vanya and Cards
- A. Vanya and Cards
- codeforces--701A Cards
- coderforces 701A Cards
- CodeForces 701A Cards
- coderforces #364 A Cards
- codeforces 701 A. Cards
- random linux skill note(Linux 命令参考)
- ecshop如何开启伪静态
- LinkedList的深入理解(学习)
- Intent跳转到系统应用中的拨号界面、联系人界面、短信界面及其他
- xcode自动打ipa包脚本
- A. Cards with Numbers
- 关系模型
- VS2012程序打包部署详解
- ImageButton的使用
- 将定制RPM包加入内部Yum Server
- Ajax异步调用代码
- Cobbler部署指南之安装篇
- too many files open
- 妥投率问题