Skip to main content
  1. Posts/

codeforces #334 div 2 B. More Cowbell

·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

题意是说。给n个balls,k个箱子。保证(n<=2*k) 一个箱子中中最多放两个balls,size为两个balls的size之和。 所有的箱子的size都要一样。 问size最小是多少。

只要让最大的size尽可能小即可。 容易想到一组贪心策略。 可以先看有几个多出来的位置 (2*k-n) 然后把最大的几个size的ball装在多余的位置里。。更新答案。 然后对于剩下的。。。最小的和最大的一组状进去。。。扫一遍更新答案。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2015年12月02日 星期三 00时00分22秒
 4File Name :code/cf/#334/B.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25
26
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=1E5+7;
34int n,k;
35int s[N];
36int a[N];
37int main()
38{
39	#ifndef  ONLINE_JUDGE
40	freopen("code/in.txt","r",stdin);
41  #endif
42	ms(s,0);
43	ms(a,0);
44	scanf("%d %d",&n,&k);
45	for ( int i = 1 ; i <= n ; i++)
46	     scanf("%d",&s[i]);
47	int duoyu = k*2-n;
48//	cout<<"duoyu:"<<duoyu<<endl;
49	int nn = n - duoyu;
50//	cout<<"nn:"<<nn<<endl;
51	int ans = -1;
52	for ( int i = nn+1 ; i <= n;i++) ans = max(ans,s[i]);
53	for ( int i = 1 ; i <= nn/2 ; i++)
54	{
55	    ans = max(ans,s[i]+s[nn-i+1]);
56//	    cout<<"i:"<<i<<" "<<s[i]<<endl;
57//	    cout<<"nn-i+1"<<nn-i+1<<" s[nn-i+1]:"<<s[nn-i+1]<<endl;
58	}
59	cout<<ans<<endl;
60
61
62  #ifndef ONLINE_JUDGE
63  fclose(stdin);
64  #endif
65    return 0;
66}

Related

codeforces 479D. Long Jumps

·2 mins
http://codeforces.com/problemset/problem/479/D 题意是说有一把尺子,本身有一些刻度,然后需要测量x和y,问最少需要添加多少个刻度,如果需要,这些刻度分别添加在什么位置。

codeforces 525 B. Pasha and String

·1 min
http://codeforces.com/problemset/problem/525/B 1题意是说一个字符串,进行m次颠倒变换(从a[i]位置到a[l-i+1]位置),问得到的字符串。容易发现,对于越在里边(对称,也就是越靠近中间位置)的字符,调换的次数越多。我们可以把a[i]从小到大排序。然后经过分析发现,把两个相邻的a[i]分为一组,做处理,如果m为奇数,最后还剩下a[m]没有被分组,要单独处理a[m]细节上要注意st数组是从st[0]开始的...好吧的确不方便,适牛也说我了。。数组下标以后还是从0开始吧。。。主要是受高中OI用的pascal的影响。。。那个数组下标随便啊。代码: 2 3 4 5 6 /* *********************************************** 7 Author :111qqz 8 Created Time :2016年02月22日 星期一 23时39分51秒 9 File Name :code/cf/problem/525B.cpp 10 ************************************************ */ 11 12 #include <iostream> 13 #include <algorithm> 14 #include <cstring> 15 #include <cmath> 16 #include <cstdio> 17 18 using namespace std; 19 20 int m,k,len; 21 const int N=2E5+7; 22 int a[N]; 23 char st[N]; 24 25 int main() 26 { 27 cin>>st; 28 scanf("%d",&m); 29 for ( int i = 1 ; i <= m ; i++ ) 30 scanf("%d",&a[i]); 31 sort(a+1,a+m+1); 32 k = 1; 33 len = strlen(st); 34 while (k<=m) 35 { 36 for ( int j = a[k] ; j <= a[k+1]-1 ; j++) 37 swap(st[j-1],st[len-j]); 38 k = k + 2; 39 } 40 if ( m %2==1 ) 41 for ( int i = a[m]; i <= len/2 ; i++ ) 42 swap(st[i-1],st[len-i]); 43 cout<<st<<endl; 44 return 0; 45 }

codeforces 482 A. Diverse Permutation(构造)

·1 min
C - C **Time Limit:**1000MS **Memory Limit:**262144KB 64bit IO Format:%I64d & %I64u Submit Status Description Permutation_p_ is an ordered set of integers _p_1, p_2, …, p__n, consisting of n distinct positive integers not larger than n. We’ll denote as_n the length of permutation _p_1, _p_2, …, p__n.