题目链接

A. Appleman and Easy Task

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?

Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.

Input

The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.

Output

Print "YES" or "NO" (without the quotes) depending on the answer to the problem.

Sample test(s)
input
3
xxo
xox
oxx
output
YES
input
4
xxxo
xoxo
oxox
xxxx
output
NO

题意 :n*n的格子,问是否每个格子都与偶数个o相邻

思路 :暴力。。。最讨厌这种怎么看都对的数据了。。。。

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include <algorithm> using namespace std ; char sh[][] ; int main()
{
int n ;
scanf("%d",&n) ;
for(int i = ; i < n ; i++)
scanf("%s",sh[i]) ;
bool flag = false ;
for(int i = ; i < n ; i++)
{
for(int j = ; j < n ; j++)
{
int cnt = ;
if(i > && sh[i-][j] == 'o') cnt ++ ;
if(i < n- && sh[i+][j] == 'o') cnt++ ;
if(j > && sh[i][j-] == 'o') cnt ++ ;
if(j < n- && sh[i][j+] == 'o') cnt ++;
if(cnt % )
{
flag = true ;break ;
}
}
if(flag) break ;
}
if(flag) puts("NO") ;
else puts("YES") ;
return ;
}

B. Appleman and Card Game

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card i you should calculate how much Toastman's cards have the letter equal to letter on ith, then sum up all these quantities, such a number of coins Appleman should give to Toastman.

Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105). The next line contains n uppercase letters without spaces — the i-th letter describes the i-th card of the Appleman.

Output

Print a single integer – the answer to the problem.

Sample test(s)
input
15 10
DZFDFZDFDDDDDDF
output
82
input
6 4
YJSNPI
output
4
Note

In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.

题意 :一共n个大写字母,从中挑出k个,这k个中的对于每个字母来说,有x个字母都为该字母,那最后的值就加上x,问最后怎么选这k个字母使得最后的值最大。

思路 :贪心,哈希一下,排序,然后从最多的开始找,要注意,这个题卡long long 。。。。。因为中间结果可能会超什么的。。。。要注意。。。。

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include <algorithm> using namespace std ; char sh[] ;
long long hashh[] ; int main()
{
long long n , k ;
// freopen("1234.txt","r",stdin) ;
// freopen("1234.txt","w",stdout) ;
while(~scanf("%I64d %I64d",&n,&k))
{
scanf("%s",sh) ;
memset(hashh,,sizeof(hashh)) ;
for(int i = ; i < n ; i++)
{
hashh[sh[i]-'A'] ++ ;
}
sort(hashh,hashh+) ;
long long sum = ;
for(long long i = k ,j = ; i > ; )
{
if(hashh[j] <= i)
{
sum += hashh[j]*hashh[j] ;
i -= hashh[j] ;
}
else
{
sum += i*i ;
i = ;
}
j-- ;
}
printf("%I64d\n",sum) ;
}
return ;
}

C. Appleman and Toastman

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks:

  • Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman.
  • Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.

After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?

Input

The first line contains a single integer n (1 ≤ n ≤ 3·105). The second line contains n integers a1a2, ..., an (1 ≤ ai ≤ 106) — the initial group that is given to Toastman.

Output

Print a single integer — the largest possible score.

Sample test(s)
input
3
3 1 5
output
26
input
1
10
output
10
Note

Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.

题意 :给T一个数组,然后他把所有的值加起来加到最后的值上,然后把这个数组给A,如果A收到的数组只有一个数,那就把这个值扔掉。否则的话A就把这个数组分成两个再送给T,然后T再把和加到最后的值上。。。。循环往复,问最后得到的最大值是多少。

思路 : 其实就是排一下序,然后每次把最小的分出去,最后统计一下每个值被加过的次数,发现最后一个是n次,倒数第二个也是n次,第一个是2次,第二个是3次,第三个是4次,第四个是5次。。。。。

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define LL long long using namespace std ; LL n ;
LL a[] ; int main()
{
while(~scanf("%I64d",&n))
{
for(int i = ; i <= n ; i++)
{
scanf("%I64d",&a[i]) ;
}
LL ans = ;
sort(a+,a+n+) ;
for(int i = ; i < n ; i++)
{
ans += a[i] * (i+) ;
// printf("sum = %I64d\n",a[i]*(i+1)) ;
// printf("ans = %I64d\n",ans) ;
}
ans += n * a[n] ;
printf("%I64d\n",ans) ;
}
return ;
}

Codeforces Round #263 (Div. 2) A B C的更多相关文章

  1. 贪心 Codeforces Round #263 (Div. 2) C. Appleman and Toastman

    题目传送门 /* 贪心:每次把一个丢掉,选择最小的.累加求和,重复n-1次 */ /************************************************ Author :R ...

  2. Codeforces Round #263 (Div. 2)

    吐槽:一辈子要在DIV 2混了. A,B,C都是简单题,看AC人数就知道了. A:如果我们定义数组为N*N的话就不用考虑边界了 #include<iostream> #include &l ...

  3. Codeforces Round #263 (Div. 1)

    B 树形dp 组合的思想. Z队长的思路. dp[i][1]表示以i为跟结点的子树向上贡献1个的方案,dp[i][0]表示以i为跟结点的子树向上贡献0个的方案. 如果当前为叶子节点,dp[i][0] ...

  4. Codeforces Round #263 Div.1 B Appleman and Tree --树形DP【转】

    题意:给了一棵树以及每个节点的颜色,1代表黑,0代表白,求将这棵树拆成k棵树,使得每棵树恰好有一个黑色节点的方法数 解法:树形DP问题.定义: dp[u][0]表示以u为根的子树对父亲的贡献为0 dp ...

  5. Codeforces Round #263 (Div. 2) D. Appleman and Tree(树形DP)

    题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input ...

  6. Codeforces Round #263 (Div. 1) C. Appleman and a Sheet of Paper 树状数组暴力更新

    C. Appleman and a Sheet of Paper   Appleman has a very big sheet of paper. This sheet has a form of ...

  7. Codeforces Round #263 (Div. 2) proC

    题目: C. Appleman and Toastman time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. Codeforces Round #263 (Div. 2)C(贪心,联想到huffman算法)

    数学家伯利亚在<怎样解题>里说过的解题步骤第二步就是迅速想到与该题有关的原型题.(积累的重要性!) 对于这道题,可以发现其实和huffman算法的思想很相似(可能出题人就是照着改编的).当 ...

  9. Codeforces Round #263 (Div. 2) proB

    题目: B. Appleman and Card Game time limit per test 1 second memory limit per test 256 megabytes input ...

随机推荐

  1. VMware共享目录设置

    1.保证虚拟机中已经成功安装了 VMware Tools (非常关键) 2.打开VMware,并使虚拟机处于关机状态,然后请按图中箭头所示进行操作 这样就大功告成了,此时进入虚拟机, 执行命令 cd  ...

  2. iOS-CALayer

    iOS开发UI篇—CAlayer层的属性 一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property ...

  3. 【热门收藏】iOS开发人员必看的精品资料(100个)——下载目录

    iPhone.iPad产品风靡全球,巨大的用户群刺激着iOS软件开发需求,然而国内人才缺口很大,正处于供不应求的状态,ios开发前景大好.我们整理了51CTO下载中心100份热门的ios开发资料,做了 ...

  4. 关于UIView需要看的一些官方文档

    View Controller PG(Programming Guide)  看过一遍 View PG 正在看 Drawing and Printing PG Quartz 2D PG 更高级的cus ...

  5. 17.Quartus 怎么回读CPLD里面的东西

    可以使用Quartus® II Programmer的“Examine”特性回读编程目标文件(.POF)是CPLD不是FPGA 先用auto检测加没加加密位,然后执行ex,然后save,Examine ...

  6. oracle增加表空间的四种方法,查询表空间使用情况

    增加表空间大小的四种方法Meathod1:给表空间增加数据文件ALTER TABLESPACE app_data ADD DATAFILE'D:\ORACLE\PRODUCT\10.2.0\ORADA ...

  7. Java Day 13

    线程的状态 被创建 运行 冻结 消亡  被创建--start()--> 运行 运行----run()----> 消亡         stop() 运行---sleep(time)---& ...

  8. P1119: [POI2009]SLO

    这题预处理稍微动动脑,其实还是个裸的置换群=-=,没什么压力. ; var n,i,j,minx,tem,now,tmin,len:longint; cursum,sum:int64; pos,num ...

  9. objective-c自学总结(二)---init/set/get方法

    一:类的声明和实现: 声明:(放在“类名+.h”文件中). 类的声明主要有两部分组成:实例变量和方法. 例 #import <Foundation/Foundation.h> @inter ...

  10. 校园导游之NABC个人分析

    校园导游之NABC个人分析 Need: 为不熟悉校园环境的人们(如新生,来咱们学校参观滴)提供便利. Approach: 了解Andriod应用开发:导航功能之外还可以对学校进行宣传,比如拍一些学校的 ...