Coderforces Rockethon 2014 Trial Contest: Testing Round #10 A2. Skis
2014-02-15 22:24
239 查看
A2. Skis
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A warehouse of the oldest sports shop of Berland received n skis, the length of the i-th
ski equals ai centimeters.
Your task is to find out the largest number of ski packs to sell if a ski pack must contain two skis and the sum of their lengths must equal exactly q centimeters.
Note that the Berland skis aren't differentiated as left or right.
Input
The first line contains two positive integers n and q.
The second line contains n positive integers a1, a2,
..., an (1 ≤ ai ≤ q).
Limits n and q are distinct for distinct problems:
for subproblem A1: 1 ≤ n, q ≤ 100,
for subproblem A2: 1 ≤ n, q ≤ 106.
Output
Print the required maximum number of packs.
Sample test(s)
input
output
n个数,求和为q的对数
统计每个数xi出现的次数记为a[x],取min(a[x],a[q-x]),求和即可,注意当x+x=q时特判
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A warehouse of the oldest sports shop of Berland received n skis, the length of the i-th
ski equals ai centimeters.
Your task is to find out the largest number of ski packs to sell if a ski pack must contain two skis and the sum of their lengths must equal exactly q centimeters.
Note that the Berland skis aren't differentiated as left or right.
Input
The first line contains two positive integers n and q.
The second line contains n positive integers a1, a2,
..., an (1 ≤ ai ≤ q).
Limits n and q are distinct for distinct problems:
for subproblem A1: 1 ≤ n, q ≤ 100,
for subproblem A2: 1 ≤ n, q ≤ 106.
Output
Print the required maximum number of packs.
Sample test(s)
input
7 51 2 1 4 3 1 3
output
2
n个数,求和为q的对数
统计每个数xi出现的次数记为a[x],取min(a[x],a[q-x]),求和即可,注意当x+x=q时特判
#include<cstdio> #include<iostream> #include<cstdlib> #include<algorithm> #include<ctime> #include<cctype> #include<cmath> #include<string> #include<cstring> #include<queue> #include<vector> #define sqr(x) (x)*(x) #define INF 0x1f1f1f1f #define PI 3.1415926535 #define mm 1000001 using namespace std; int a[mm],n,q,x,cnt; int main() { scanf("%d%d",&n,&q); memset(a,0,sizeof(a)); for (int i=0;i<n;i++) { scanf("%d",&x); a[x]++; } cnt=0; for (int i=0;i<q;i++) //这里到q/2就可以了 { if (q%2==0 && i==q>>1) { cnt+=(a[i]>>1); a[i]=0; continue; } cnt+=min(a[i],a[q-i]); a[i]=a[q-i]=0; } printf("%d\n",cnt); return 0; }
相关文章推荐
- Codeforces Rockethon 2014 C题
- Codeforces Rockethon 2014 解题报告
- 【Codeforces Rockethon 2014】Solutions
- codeforces 391E2 (【Codeforces Rockethon 2014】E2)
- codeforces 391E2 (【Codeforces Rockethon 2014】E2)
- codeforces Rockethon 2014 A
- Codeforces Rockethon 2015
- Codeforces Coder-Strike 2014 (Div. 2) C: Online Meeting 来得最早走得最晚的leader
- Codeforces Round Rockethon 2015
- codeforces Coder-Strike 2014 Round 1 C题解题报告
- codeforces Coder-Strike 2014 Round 1 B题解题报告
- codeforces Rockethon 2015 - A. Game (= =)
- codeforces Coder-Strike 2014 Round 1 A题解题报告
- Codeforces Coder-Strike 2014 - Finals (online edition, Div. 1)
- codeforces Rockethon 2015 C Second price auction [想法]
- Rockethon 2014 A. Genetic Engineering
- Rockethon 2014 B. Word Folding
- codeforces Rockethon 2015
- Codeforces Rockethon 2015 解题报告
- CODEFORCES Rockethon 2015 B. Permutations