昨天没打,今天写了一下,前三题都没有难度吧。

A. Appleman and Easy Task
time limit per test

1 second

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

题意:推断一个点的上下左右四个方向’o'的个数,都是偶数输出YES。否则输出NO。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<vector>
typedef long long LL;
using namespace std;
char mp[110][110];
int n; int main()
{
while(cin>>n)
{
int ok=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cin>>mp[i][j];
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
int cnt=0;
if(mp[i+1][j]=='o')
cnt++;
if(mp[i-1][j]=='o')
cnt++;
if(mp[i][j-1]=='o')
cnt++;
if(mp[i][j+1]=='o')
cnt++;
if(cnt&1)
{
ok=0;
break;
}
}
}
if(ok) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
B. Appleman and Card Game
time limit per test

1 second

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.


水题,hash后排序计算就可以。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<vector>
typedef long long LL;
using namespace std;
int hash[30];
int cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,k;
char c;
while(cin>>n>>k)
{
memset(hash,0,sizeof(hash));
for(int i=0;i<n;i++)
{
cin>>c;
hash[c-'A']++;
}
sort(hash,hash+26,cmp);
LL sum=0;
for(int i=0;i<26;i++)
{
if(k==0) break;
if(k>=hash[i])
{
sum+=(LL)hash[i]*hash[i];
k-=hash[i];
}
else
{
sum+=(LL)k*k;
k=0;
}
}
cout<<sum<<endl;
}
return 0;
}
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 a1, a2,
..., 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.


计数问题,每次抛出一个最小的数就可以得到最大值。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<vector>
typedef long long LL;
using namespace std;
LL num[300000+100];
int main()
{
int n;
while(~scanf("%d",&n))
{
LL sum=0;
for(int i=1;i<=n;i++)
scanf("%d",&num[i]);
sort(num+1,num+n+1);
for(int i=1;i<=n;i++)
sum+=num[i]*(i+1);
cout<<sum-num[n]<<endl;
}
return 0;
}

CF#263的更多相关文章

  1. 3.26-3.31【cf补题+其他】

      计蒜客)翻硬币 //暴力匹配 #include<cstdio> #include<cstring> #define CLR(a, b) memset((a), (b), s ...

  2. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  3. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  4. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  5. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  6. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  7. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  8. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  9. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

随机推荐

  1. 【转】__attribute__机制介绍

    1. __attribute__ GNU C的一大特色(却不被初学者所知)就是__attribute__机制. __attribute__可以设置函数属性(Function Attribute).变量 ...

  2. IT人士的职业规范——凝视

     这两天将系统敲完了,该总体调试了,调试的过程中,发现了一个非常大的问题,就是自己的凝视写的不够,有时候不明确U层这个事件是做什么的,有时候不知道这个事件传递的是什么參数,有时候不知道相应的B层和 ...

  3. OpenStack 部署总结之:在CentOS 6.5上使用RDO单机安装icehouse(Ml2+GRE)

    本文主要介绍怎样在CentOS6.5上通过RDO来安装icehouse,因为安装的过程中涉及的软件较多,以及依赖关系比較复杂,建议使用一个全新的操作系统来进行安装. 安装步骤详细例如以下 (1)安装操 ...

  4. PCI、PCIE配置空间的訪问(MCFG,Bus,Device,Funtion)

    一般来说,在x86平台上,有两大类方式能够訪问这一区间的寄存器,   1,配置机制1#或者配置机制2#   訪问时借助in/out指令.请注意,这样的方式有别于一般的in/out指令訪问PCI的IO空 ...

  5. poj 3308 (最大流)

    题意:n*m的地图,给出L个火星人登陆的坐标,要在火星人登陆地球的瞬间全部消灭他们,有一种激光枪,一次可以消灭一行(或一列),消灭一行(或一列)有不同的代价,总代价是所有激光枪的代价之积. 思路:之前 ...

  6. MySQL中explain的type类型

    |  ALL              |  全表扫描 |  index            |  索引全扫描 |  range            |  索引范围扫描,常用语<,<= ...

  7. sybase用户管理(创建、授权、删除)

    一.登录用户管理:1.创建用户:sp_addlogin loginame, passwd [, defdb] [, deflanguage] [, fullname] [, passwdexp] [, ...

  8. 监控代码运行时长 -- StopWatch用法例程

    在.net环境下,精确的测量出某段代码运行的时长,在网络通信.串口通信以及异步操作中很有意义.现在做了简单的总结.具体代码如下: (1).首先 using System.Diagnostics; (2 ...

  9. mysql 服务不见了的解决办法

    昨天打开电脑mysql突然连接不了了,去服务里找,却找不到mysql服务了 解决:5.0版本:开始->运行->cmd,进到mysql安装的bin目录D:\MySQL\bin>mysq ...

  10. Deppon接口开发

    一.1)  支持的传输协议  http ,暂时只支持HTTP协议进行通信. (2) 支持的数据传输格式  Json  ,所有接口暂只支持json消息格式. (3) 编码格式:UTF-8   交互编码格 ...