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 2
aabb
output
YES
input
6 3
aacaab
output
NO

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

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
4
1 3 2 3
output
First
input
2
2 2
output
Second

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

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
5
7 3 5 3 4
2 1 3 2 3
output
4 7 3 5 3
input
7
4 6 5 8 8 2 6
2 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[];
pair<int, int> b[]; int ansa[]; int main() {
cin >> n;
for (int i = ; i < n; i++) {
cin >> a[i].first;
a[i].second = i;
}
for (int i = ; i < n; i++) {
cin >> b[i].first;
b[i].second = i;
} sort(a, a + n);
sort(b, b + n); for (int i = ; i < n; i++) {
ansa[b[i].second] = a[n - - i].first;
} for (int i = ; i < n; i++) {
printf("%d ", ansa[i]);
} return ;
}

codeforces Round#429 (Div2)的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  3. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

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

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

  5. CodeForces 840B - Leha and another game about graph | Codeforces Round #429(Div 1)

    思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上 ...

  6. CodeForces 840A - Leha and Function | Codeforces Round #429 (Div. 1)

    /* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #includ ...

  7. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  8. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  9. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

随机推荐

  1. Spark源码分析 – Dependency

    Dependency 依赖, 用于表示RDD之间的因果关系, 一个dependency表示一个parent rdd, 所以在RDD中使用Seq[Dependency[_]]来表示所有的依赖关系 Dep ...

  2. H5应用程序缓存 - Cache manifest

    一.作用 离线浏览 - 根据文件规则把资源缓存在本地,脱机依然能够访问资源,联网会直接使用缓存在本地的文件.优化加载速度,节约服务器资源. 二.适用场景 正如 manifest 英译的名字:离线应用程 ...

  3. 【keras框架】

    更高级别的封装.更简单的api,以tensorflow.theano为后端,支持更多的平台 读取网络模型后生成网络结构图 读取 from keras.models import load_model ...

  4. DevExpress控件学习总结

    1.Navigation & Layout 1.1 Bar Manager 如果想在窗体或用户控件(user control)上添加工具条(bars)或弹出菜单(popup menus),我们 ...

  5. 详解MySQL第三篇—DCL语句

    DCL(Data Control Language)语句:数据控制语句,用于控制不同数据段直接的许可和访问级别的语句.这些语句定义了数据库.表.字段.用户的访问权限和安全级别.主要的语句关键字包括 g ...

  6. 关于Softnet的加密。方式是使用API函数。。关键是开发号

    首先是获取 开发号. 类似于这个玩意 http://www.cnblogs.com/wenluderen/p/4853563.html 这个帖子里面有介绍关于开发号的完整资料. ××××××××××× ...

  7. Git-从远程仓库克隆

    本人拜读了廖雪峰老师关于Git的讲述后整理所得 上次我们讲了先有本地库,后有远程库的时候,如何关联远程库. 现在,假设我们从零开发,那么最好的方式是先创建远程库,然后,从远程库克隆. 首先,登陆Git ...

  8. js的同步异步

    由于js没有多线程,所以处理多任务的时候,可以用异步回调来解决.js中setTimeout.setInterval.ajax(jq中可以选择同步或异步)均会开启异步.遇到异步模块,会将其推入值任务队列 ...

  9. oracle 分区表详解

    一.分区表的概述: Oracle的表分区功能通过改善可管理性.性能和可用性,从而为各式应用程序带来了极大的好处.通常,分区可以使某些查询以及维护操作的性能大大提高.此外,分区还可以极大简化常见的管理任 ...

  10. oracle存储过程(返回列表的存储结合游标使用)总结 以及在java中的调用

    这段时间开始学习写存储过程,主要原因还是因为工作需要吧,本来以为很简单的,但几经挫折,豪气消磨殆尽,但总算搞通了,为了避免后来者少走弯路,特记述与此,同时亦对自己进行鼓励. 以下是我在开发项目中第一次 ...