codeforces Round#377

来源:互联网 发布:如何在淘宝上买发票 编辑:程序博客网 时间:2024/05/16 01:38

codeforces Round#377


表示还是只会水题:虽然这次做出了三题,但是前三题都是思维题吧,到了D题就不会了,还好吧,昨晚涨了100多分;

A. Buy a Shovel


题意:有若干个单位是10 的和一个单位是m的硬币,然后为刚好买多少个n才能使得不用找零;

思路:枚举,当n * i 是10的倍数或者 % 10 == m 的时候跳出;


#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 100000 + 10;int main(){    ll n,m;    while( ~ scanf("%I64d%I64d",&n,&m) )    {        for(ll i = 1; i <  maxn * maxn ; i ++)        {            if(i * n % 10 == 0 || (i * n % 10 == m))            {                cout << i << endl;                break;            }        }    }    return 0;}

B. Cormen — The Best Friend Of a Man

题意:输入一个n,m;然后要使得大小为n的数组所有相邻的两个数之和大于等于m;求使得原来的数组实现这个功能要至少增加多少个单位,并输出;

思路:直接暴力,看两个相邻的两个数之和是否大于等于m,不是的就对后面的进行变化


#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 100000 + 10;int a[maxn];int main(){    ll n,m;    while( ~ scanf("%I64d%I64d",&n,&m) )    {        for(int i = 1; i <= n ;i ++)        {            scanf("%d",&a[i]);        }        ll ans = 0;        for(int i = 2; i <= n ;i ++)        {            if(a[i] + a[i - 1] < m)            {                ans += m - a[i] - a[i - 1];                a[i] = m - a[i - 1];            }        }        cout << ans << endl;        for(int i = 1; i <= n ;i ++)        {            if(i < n)            cout << a[i] <<" ";            else cout << a[i] << endl;        }    }    return 0;}

C. Sanatorium


题意:输入的是早餐,中餐,晚餐的数量,可以在任意时间来或者离开,然后求出它他最少误了多少餐?

思路:列举所有正常的情况:1,0,0;  0,1,0 ;  0,0,1;1,1,0;  1,0,1; 0,1,1; 1,1,1;


所以对于所有的早餐,中餐,晚餐,所有的情况都是一样的,所以先对他们进行一个从小到大的排序,再对两个小的补数进行了;


#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 100000 + 10;int a[maxn];int main(){    ll n,m,k;    while( ~ scanf("%I64d%I64d%I64d",&n,&m,&k) )    {        if(m == n && m == k)            cout << 0 << endl;        else        {            ll c = max(n,max(m,k)),a = min(n,min(m,k)), b = n + m + k - a - c;            if(a == b || b == c)            {                if(a == b)                cout << 2*c - a - b - 2 << endl;                else cout << b - a - 1 << endl;            }            else cout << 2 * c - a - b  - 2<< endl;        }    }    return 0;}













0 0
原创粉丝点击