Codeforces Round #356 (Div. 2) Jun/09/2016

CodeForces-Round-356

水惨了,只能在四十分钟左右做出两题,C题gg,卡一个小时……


A. Bear and Five Cards

A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.

Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.

He is allowed to at most once discard two or three cards with the same number. Of course, he won’t discard cards if it’s impossible to choose two or three cards with the same number.

Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?

Input
The only line of the input contains five integers t1, t2, t3, t4 and t5 (1 ≤ ti ≤ 100) — numbers written on cards.

Output
Print the minimum possible sum of numbers written on remaining cards.

Examples
input
7 3 7 3 20
output
26
input
7 9 3 1 8
output
28
input
10 10 10 10 10
output
20
Note
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.

Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40.
Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26.
Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.

In the second sample, it’s impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.

In the third sample, all cards have the same number. It’s optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.

题意:在他们的sum里面去掉两个或者三个相同数的和(2*a OR 3*a)使得他们的sum最小

#include"iostream"
#include"cstring"
#include"cstdio" 
using namespace std;
int main(){
    int t[10],num[150];
    while(~scanf("%d",&t[1])) {
        int sum = t[1]; 
        for(int i=2;i<=5;i++){
            scanf("%d",&t[i]);
            sum +=t[i]; 
        }
        memset(num,0,sizeof(num)); 
        for(int i=1;i<=5;i++){
            for(int j=1;j<=5;j++){
                if(j==i) continue;
                if(t[j]==t[i]) {
                    num[t[i]]++; 
                    if(num[t[i]]>3)  num[t[i]]=3;
                }
            }
        }
        int nu,ma;
        ma = 0;
        for(int i=1;i<=100;i++){//t值变化 
            if(num[i]!=0){  
                nu = num[i]*i; 
                ma = ma>nu?ma:nu; 
            } 
        } 
        cout<<sum-ma<<endl;
    }
    return 0;
}

B. Bear and Finding Criminals

There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance between cities i and j is equal to |i - j|.

Limak is a police officer. He lives in a city a. His job is to catch criminals. It’s hard because he doesn’t know in which cities criminals are. Though, he knows that there is at most one criminal in each city.

Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city a. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.

You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.

Input
The first line of the input contains two integers n and a (1 ≤ a ≤ n ≤ 100) — the number of cities and the index of city where Limak lives.

The second line contains n integers t1, t2, …, tn (0 ≤ ti ≤ 1). There are ti criminals in the i-th city.

Output
Print the number of criminals Limak will catch.

Examples
input
6 3
1 1 1 0 1 0
output
3
input
5 2
0 0 0 1 0
output
1
Note
这里写图片描述

题意:dis从0-n遍历,考虑溢出情况,统计 当前点ai在距离 ai的dis(【a-dis】or【ai+dis】)处 位置i的a[i] (a[i] == value) 为1的数量——最后的Sum也就是Detector可以抓到的 criminals 数量

#include"iostream"
#include"cstdio" 
using namespace std;
int main(){
    int n,a[150],ai;
    while(~scanf("%d%d",&n,&ai)) {
        for(int i=1;i<=n;i++){ //value
            scanf("%d",&a[i]); 
        }
        int num = 0;
        for(int i=0;i<=n;i++){ //distance
            if(ai+i>n && ai-i<1){
                break;
            }
            if(ai+i<=n && ai-i<1){
                if(a[ai+i]==1){ num++;} 
                continue;
            }
            if(ai+i>n && ai-i>=1){
                if(a[ai-i]==1){ num++;} 
                continue;
            }
            if(a[ai+i]==1 && a[ai-i]==1){
                if(i!=0) num++;
                num++;
            }
        }
        printf("%d\n",num);
    } 
    return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值