2017-08-20 10:00:37

writer:pprp

用头文件#include <bits/stdc++.h>很方便

A. Generous Kefa codeforces 841 A

题目如下:

One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.

Next line contains string s — colors of baloons.

Output

Answer to the task — «YES» or «NO» in a single line.

You can choose the case (lower or upper) for each letter arbitrary.

Examples
input
4 2aabb

output
YES

input
6 3aacaab

output
NO

统计某个字符数量是否超过给定人数即可(水题)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>using namespace std;char ch[110];
int num[110];
int Max = -9999;
int buck[30];int main()
{int n, k;cin >> n >> k;memset(num, 0 , sizeof(num));memset(buck, 0, sizeof(num));for(int i = 0 ; i < n ; i++){cin >> ch[i];num[i]  = ch[i] - 'a';}for(int i = 0 ; i < n ;i++){buck[num[i] ]++;}for(int i = 0 ; i < 30 ; i++){if(Max < buck[i])Max = buck[i];}if(Max > k)cout << "NO" << endl;elsecout << "YES" << endl;return 0;
}

B. Godsend codeforces 841B

题目如下:

Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?

Input

First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array.

Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

Output

Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).

Examples
input
41 3 2 3

output
First

input
22 2

output
Second

分析:找规律的题目,经过多次举例可以看出 单数占优势, 偶数占劣势所以仅需要判断是否一开始就是偶数就可以,注意要用scanf 不要用 cinAC代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>using namespace std;
typedef long long ll;int main()
{int n;ll tmp;scanf("%d",&n);int cntodd = 0;int cnteven = 0;for(int i = 0 ; i < n; i++){scanf("%lld",&tmp);if(tmp & 1)cntodd++;elsecnteven++;}if(cntodd == 0)cout << "Second" << endl;elsecout << "First" << endl;return 0;
}

codeforce 841 C

C. Leha and Function

题目如下:

Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set[1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element among all k-element subsets.

But only function does not interest him. He wants to do interesting things with it. Mom brought him two arrays A and B, each consists ofm integers. For all i, j such that 1 ≤ i, j ≤ m the condition Ai ≥ Bj holds. Help Leha rearrange the numbers in the array A so that the sum  is maximally possible, where A' is already rearranged array.

Input

First line of input data contains single integer m (1 ≤ m ≤ 2·105) — length of arrays A and B.

Next line contains m integers a1, a2, ..., am (1 ≤ ai ≤ 109) — array A.

Next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 109) — array B.

Output

Output m integers a'1, a'2, ..., a'm — array A' which is permutation of the array A.

Examples
input
57 3 5 3 42 1 3 2 3

output
4 7 3 5 3

input
74 6 5 8 8 2 62 1 2 2 1 1 2

output
2 6 4 5 8 8 6

题意很不好理解,观察数据以后发现所谓的期望就是几分之几

比如: 第一个例子中

7 3 5 3 4

2 1 3 2 3

期望为:2 / 7 + 1 / 3 + 3 / 5 + 2 / 3 + 3 / 4

题目要求期望最大值,那么要将分子中最小的与分母中最大的进行匹配

比较坑的一点是,如果分子相同,那么该如何处理?

本来以为应该从小到大排序,但是之后看的时候并没有要求怎么排序

所以用sort pair就可以解决了

一开始本来想用multimap来着,但是没有必要

用pair进行排序就可以了,sort只能排序线性的容器,所以也不能对map进行排序(虽然map中按key已经排好了)

代码如下:

#include<bits/stdc++.h>using namespace std;int n;pair<int, int> a[200008];
pair<int, int> b[200008];int ansa[200008];int main() {cin >> n;for (int i = 0; i < n; i++) {cin >> a[i].first;a[i].second = i;}for (int i = 0; i < n; i++) {cin >> b[i].first;b[i].second = i;}sort(a, a + n);sort(b, b + n);for (int i = 0; i < n; i++) {ansa[b[i].second] = a[n - 1 - i].first;}for (int i = 0; i < n; i++) {printf("%d ", ansa[i]);}return 0;
}

转载于:https://www.cnblogs.com/pprp/p/7399073.html

codeforces Round#429 (Div2)相关推荐

  1. CodeForces 840C - On the Bench | Codeforces Round #429 (Div. 1)

    思路来自FXXL中的某个链接 /* CodeForces 840C - On the Bench [ DP ] | Codeforces Round #429 (Div. 1) 题意:给出一个数组,问 ...

  2. Codeforces Round#310 div2

    C题:这题说的是套娃,如果做题的时候知道是套娃,那就好理解多了 规则1:套娃A可以放到套娃B里面,当且仅当套娃B没有放在其他套娃里面 规则2:套娃A放在套娃B里面,且套娃B没有放在其他套娃里面,那么可 ...

  3. Codeforces Round #359 div2

    Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...

  4. Codeforces Round #429 (Div. 2) B. Godsend

    Problem - B - Codeforces 题意: 给定一个数列,先手可以remove一段区间和为奇数的区间,后手可以remove一段区间和为偶数的区间,问你赢家是谁? 思路: 博弈题按状态的思 ...

  5. Codeforces Round 361 div2

    雪崩,全错掉了GG.前两道题相对之前的难度大一点啊,不过A题有个循环应该是从0开始而不是1开始这样的低级错误不应该犯.B题差不多是一个BFS,但是我当时始终绕着最短路径写来写去,一直各种TLE与WA. ...

  6. Codeforces Round #360(div2)

    考完试的晚上,打了场codeforces,主要感觉由于睡眠不够,最后差了点劲啊,C题基本上都过了,但忙中出错最后把数组调小易于debug后再提交又忘记改回来了,看到Runtime Error自己竟没反 ...

  7. codeforces round 416 div2补题

    第一题,水题 A. Vladik and Courtes #include<bits/stdc++.h> using namespace std; int main() {long lon ...

  8. codeforces round 421 div2 补题 CF 820 A-E

    A Mister B and Book Reading  O(n)暴力即可 #include<bits/stdc++.h> using namespace std; typedef lon ...

  9. codeforces round #576 div2 D Welfare State(线段树)[单点修改+区间修改]

    题意:有一些数字,以及一些操作.操作一是单点修改,输入1 b c,将位置b改成c,操作二是输入2 a,将不大于a的数全部改成a.求更改完毕后的数. tag的运用:tag是对被覆盖区间上加一个标记,那么 ...

最新文章

  1. PCL之C++动态内存学习
  2. 基于 Kafka + Flink + Redis 的电商大屏实时计算案
  3. MySQL—相关子查询
  4. 关于linux系统下文件压缩归档操作命令略提
  5. 大数据WEB阶段(十二)会话技术、Cookie、Session及两者的区别
  6. 线程池简单实现java_简单实现java线程池
  7. 给IT新人的15个建议:程序员的辛酸反省与总结!
  8. DAS 2020 诚征论文及赞助!
  9. spark视频-Spark on Yarn
  10. 在Visual Studio 2017中找不到.NET Framework 4.6.2
  11. MySQL Partition扫盲
  12. 汇编语言指令系统——控制转移类指令
  13. 行政区划矢量数据介绍与下载教程
  14. bin文件夹下的roslyn文件夹
  15. 关于常用第三方统计平台比较
  16. 真正带你搞懂RecyclerView的缓存机制,Android岗
  17. echarts的饼图制作分析
  18. 勒索病毒威胁的解决方案
  19. Java 实现数据脱敏的技术方案
  20. C语言程序设计 密码开锁 指针的介绍

热门文章

  1. nik collection滤镜
  2. swoole 简单的聊天室
  3. ContrainedBox:设置尺寸
  4. 微信小程序篇(微信小程序的支付)
  5. 第一章 自定义MVC框架
  6. 读取cc2530节点的设备类型、协调器、路由器、终端。
  7. 【转】TCP协议中的三次握手和四次挥手(图解)
  8. 【转载】C++创建对象的两种方法
  9. 在quartus 和 ISE 里直接调用modelsim的方法(转)
  10. Range在各浏览器下的问题和常见处理办法