Codeforces Round #263 (Div. 2) A、B、C【淼】

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<cstdio>
#include<cmath>
#include<cstring>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define INF 0x7FFFFFFF
#define INT_MIN -(1<<31)
#define eps 10^(-6)
#define Q_CIN ios::sync_with_stdio(false)
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define REV( i , n ) for ( int i = n - 1 ; i >= 0 ; -- i )
#define FOR( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define FOV( i , a , b ) for ( int i = a ; i >= b ; -- i )
#define CLR( a , x ) memset ( a , x , sizeof (a) )
#define RE freopen("in.txt","r",stdin)
#define WE freopen("out.txt","w",stdout)
#define NMAX 10002
int n;
char a[105][105];
bool isok(int x,int y)
{
    if(x >= 0 && x < n)
        if(y >= 0 && y < n)
            if(a[x][y] == 'o')
                return true;
    return false;
}
int main()
{
   // RE;
	int cnt;
	bool flag;
	while(scanf("%d%*c", &n)==1)
    {
        REP(i,n)
            gets(a[i]);
        flag = true;
        REP(i,n)
        {
            cnt = 0;
            REP(j,n)
            {
                if(isok(i-1,j)) cnt++;
                if(isok(i,j-1)) cnt++;
                if(isok(i+1,j)) cnt++;
                if(isok(i,j+1)) cnt++;
                if(cnt % 2)
                {
                    flag = false;
                    break;
                }
            }
        }
        if(flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
	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.


还是看题意的水题

// believe ChunGe,get AC
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define INF 0x7FFFFFFF
#define INT_MIN -(1<<31)
#define eps 10^(-6)
#define CLR(a,x) memset(a,x,sizeof(a));//0,-1,true,false
#define Q_CIN ios::sync_with_stdio(false);
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define FIN freopen("in.txt","r",stdin);
#define FOUT freopen("out.txt","w",stdout);
#define NMAX 10002
bool cmp(int a,int b)
{
    return a > b;
}
int main()
{
    ll times[27],k,ans;
    int ch,n;
	scanf("%d%I64d%*c",&n,&k);
	CLR(times,0);
	for(int i=0;i<n;i++)
    {
        ch = getchar()-'A';
        times[ch]++;
    }
    sort(times,times+27,cmp);
    ans = 0;
    for(int i=0;i<27;i++)
    {
        if(times[i] >= k)
        {
            ans += k*k;
            break;
        }else
        {
            ans += times[i]*times[i];
            k -= times[i];
        }
    }
    printf("%I64d\n",ans);
	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 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.


每次加上并丢掉最小的那个,也加上剩余那些的和,我一想就是优先队列,每次弹出最小的,求和即可,基础类型变量要最小优先的,入列直接加负号

93MS 6700K

#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define INF 0x7FFFFFFF
#define INT_MIN -(1<<31)
#define eps 10^(-6)
#define CLR(a,x) memset(a,x,sizeof(a));//0,-1,true,false
#define Q_CIN ios::sync_with_stdio(false);
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define FIN freopen("in.txt","r",stdin);
#define FOUT freopen("out.txt","w",stdout);
#define NMAX 10002

priority_queue<ll>q;
ll ans,sum,num;
void f()
{
    ll fir;
    while(!q.empty())
    {
        fir = q.top();
        fir = -fir;
        q.pop();
        ans += sum;
        sum -= fir;
        ans += fir;
    }
    ans -= fir;
    printf("%I64d\n",ans);
}

int main()
{
	int n;
    scanf("%d",&n);
    {
        sum = 0;
        while(!q.empty())
            q.pop();
        for(int i=0;i<n;i++)
        {
            scanf("%I64d",&num);
            sum += num;
            q.push(-num);
        }
        f();
	}
	return 0;
}
直接模拟 93MS 2400K

#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define NMAX 300010

ll ans,sum,num;
ll a[NMAX];
int main()
{
	int n;
    scanf("%d",&n);
    {
        ans = sum = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%I64d",&a[i]);
            sum += a[i];
        }
        sort(a,a+n);
        ans += sum;
        for(int i = 0; i < n; i++)
        {
            ans += a[i];
            sum -= a[i];
            ans += sum;
        }
        ans -= a[n-1];
        printf("%I64d\n",ans);
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值