↓ Skip to main content
  1. Posts/

codeforces 373 C. Counting Kangaroos is Fun

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

http://codeforces.com/contest/373/problem/C 题意:n个袋鼠,每个袋鼠的size为a[i],一只袋鼠的size至少是另一只两倍时才能将它装下,被装下的袋鼠不能再装别的袋鼠且不能被看见。问能看见的袋鼠最少是多少。 思路:贪心。最多有n/2个袋鼠被装下。先排序,然后贪心即可。

代码实现
 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月18日 星期四 14时32分29秒
 4File Name :code/cf/problem/373C.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#define pi pair < int ,int >
26#define MP make_pair
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=5E5+7;
34int a[N];
35int n;
36int main()
37{
38	#ifndef  ONLINE_JUDGE
39	freopen("code/in.txt","r",stdin);
40  #endif
41	cin>>n;
42	for ( int i = 1 ; i <= n ; i++) scanf("%d",&a[i]);
43
44	sort(a+1,a+n+1);
45
46	int j = n;
47	int ans = 0 ;
48	for (int  i = n/2 ;  i >=1 ; i--)
49	{
50	    if (a[j]>=2*a[i])
51	    {
52		ans++;
53		j--;
54	    }
55	}
56	cout<<n-ans<<endl;
57
58
59  #ifndef ONLINE_JUDGE
60  fclose(stdin);
61  #endif
62    return 0;
63}

Related

uva 10785 The Mad Numerologist

·753 words·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1726 题意:给出26个大写字母的权值,要求构造一个长度为n(n不超过210)的字符串。并且满足奇数位置只能放元音字母,偶数位置只能放辅音字母,且每个元音字母最多放21次,每个辅音字母最多放5次,要求构造的字符串的权值之和最小,在权值最小的前提下字典序最小。

codeforces 12 C. Fruits

·432 words·1 min
http://codeforces.com/contest/12/problem/C 题意:有n个价格价格,m个要买的东西(可能有相同的种类,设为k种),把n个标签中拿出k个给个贴上。。。问最大价钱和最少价钱分别是多少。 思路:贪心。不过要按照map的value排序。。然后发现其实不用排序。。因为map的key值其实不影响。

codeforces 526 B Om Nom and Dark Park

·281 words·1 min
http://codeforces.com/contest/526/problem/B 题意:有一棵完全二叉树。每条边上有一定数量的路灯。问最少需要添加多少个路灯。使得根节点道叶子节点的每一条路径上的路灯数量一样。 思路:同叶子节点网上更新即可。 代码实现 1/* *********************************************** 2Author :111qqz 3Created Time :2015年12月11日 星期五 16时57分27秒 4File Name :code/cf/problem/526B.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#define pi pair < int ,int > 26#define MP make_pair 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=3E3+7; 34int n; 35int a[N]; 36int main() 37{ 38 #ifndef ONLINE_JUDGE 39 freopen("code/in.txt","r",stdin); 40 #endif 41 cin>>n; 42 LL res = 0 ; 43 n = (2<<n)-2; 44 for ( int i = 1 ; i <= n ; i++) 45 { 46 cin>>a[i]; 47 } 48 for ( int i = n ; i >= 1 ; i-=2) 49 { 50 res +=abs(a[i]-a[i-1]); 51 if (i!=2) a[i/2-1] += max(a[i],a[i-1]); 52 } 53 cout<<res<<endl; 54 55 56 #ifndef ONLINE_JUDGE 57 fclose(stdin); 58 #endif 59 return 0; 60}

cf 596 B. Wilbur and Array

·386 words·1 min
http://codeforces.com/problemset/problem/596/B 题意:初始序列全为0,问经过多少次变换,能变成序列b。一次变换是指,选定一个i,从i一直到最后每个元素都增加1,或者每个元素都减少1. 思路:很容易发现。后面的变换补影响前面的变换。每一个数字可以唯一由之前的增加和减少次数决定。所以我们用两个变量,记录之前做的增加和减少变换的次数。然后扫一遍即可。

codeforces 600 C. Make Palindrome

·742 words·2 mins
http://codeforces.com/problemset/problem/600/C 题意:给定一个字符串。要求用最少的变换得到一个回文串。且在变换次数相同时要字典序最小的。输出变换后的字符串。 思路:对不能构成会文串有影响的是出现奇数次的字母。所以我们先统计每个字母出现的次数。然后按照出现奇数次的字母的个数分奇偶分别搞。偶数的话直接把后面一半变成前面一半。奇数的话,也是这样。输出的时候按照字母从a扫到z,如果有就输出一半。然后再倒着扫一遍。 输出另一半。这样可以保证是字典序最小。需要注意的是奇数的时候的输出情况。不要忘记中间那个字母。