国庆10.4

版权声明:莉莉莉 https://blog.csdn.net/qq_41700151/article/details/83097033

A - ACodeForces 1047A
题目题目

题意就是给一个数,把他分成三个数,这三个数求余3都不等于0
如果是3的倍数,就分出来两个1
如果不是就分出来一个1,一个2

#include<iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f
const int MAX=1e6;
using namespace std;
int main()
{
    int n,a,b,c,ans;
    cin>>n;
    a=n/3,b=n/3,c=n/3;
    if(a%3!=0&&b%3!=0&&c%3!=0&&3*a==n)
    {
        cout<<a<<" "<<b<<" "<<c<<endl;
        return 0;
    }
    if(n%3==0)
    {
        a=1;
        b=1;
        c=n-2;
    }
    else
    {
       a=1;
       b=2;
       c=n-3;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;

}

B - BCodeForces 1047B
题目题目

#include<iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f
const int MAX=1e6;
using namespace std;
int main()
{
    ll x,y,sum;
    ll ans=-1;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%lld%lld",&x,&y);
        sum=x+y;
        if(sum>ans)
            ans=sum;

    }
    printf("%lld\n",ans);
    return 0;

}

C - CCodeForces 816A
输入一个时间,找这个时间到下一个回文的时间的相差的分钟数

#include<iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f
const int MAX=1e6;
using namespace std;
int s[25][70];
int main()
{
    int a,b;
    scanf("%d:%d",&a,&b);
    memset(s,0,sizeof(s));
    s[0][0]=1;
    for(int i=1; i<=23; i++)
        for(int j=0; j<=59; j++)
        {
            if(i<=9)
            {
                if(j%10==0&&j/10==i)
                    s[i][j]=1;
            }
            else
            {
                if(j%10==i/10&&j/10==i%10)
                    s[i][j]=1;
            }
        }

    int sum=0,flag=0;
    for(int j=b;j<=59;j++)
    {
        if(s[a][j]==1)
           break;
        sum++;
    }
    if(sum+b<60)    //到下个点的时间不过一小时
    {
        cout<<sum<<endl;
        return 0;
    }
    for(int i=a+1; i<=23; i++)    //超过一个小时
    {
        for(int j=0; j<=59; j++)
        {
            if(s[i][j]==1)
            {
                flag=1;
                break;
            }
            sum++;
        }
        if(flag==1)
            break;
    }
    printf("%d\n",sum);
    return 0;


}

D - DCodeForces 816B
Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed “The Art of the Covfefe”.

She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between li and ri degrees, inclusive, to achieve the optimal taste.

Karen thinks that a temperature is admissible if at least k recipes recommend it.

Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?

Input
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.

The next n lines describe the recipes. Specifically, the i-th line among these contains two integers li and ri (1 ≤ li ≤ ri ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between li and ri degrees, inclusive.

The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.

Output
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.

Sample Input
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
给你n,k,q,
n代表n本书,每本书上都写着咖啡最好的温度区间,如果有k本及以上都写了某一个温度,就认为这个温度是好的,有q次询问,输出询问的温度区间内是好的温度的温度有几个
用类似于前缀和的一种思想,一开始用map一直T

#include<iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
const int MAX=1e6;
using namespace std;
int ans[200000+5];
int sum[200000+5];
int main()
{
    int n,k,q,a,b;
    int d=0;
    int minn=INF,maxx=-1;
    scanf("%d%d%d",&n,&k,&q);
    memset(ans,0,sizeof(ans));
    for(int i=0; i<n; i++)
    {
        cin>>a>>b;
        if(a<minn)
            minn=a;
        if(b>maxx)
            maxx=b;
        ans[a]++;
        ans[b+1]--;

    }

    for(int i=minn+1; i<=maxx; i++)
        ans[i]+=ans[i-1];
    int cnt=0;
    for(int i=1; i<=200000; i++)        
    {
        if(ans[i]>=k)
            cnt++;
        sum[i]=cnt;

    }    
    for(int i=0; i<q; i++)
    {
        scanf("%d%d",&a,&b);

        printf("%d\n",sum[b]-sum[a-1]);


    }
    return 0;
}

E - E CodeForces 816C
题目在这里
题意:就是一个小孩玩游戏,每次只能给每一行或者每一列减1,如果能通过一系列的操作,把所有的数都变成0,就输出每次要操作的行号或者列号,不能就输出-1

一开始存行号和列号的数组开小了,WA7在codeforces上显示输出-1,在cb上却能运行出来那500多个数,这个题要算两次,先处理行再处理列,和先处理列再处理行,然后比较哪个处理的次数少,就输出哪个
一个长代码

#include<iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f
const int MAX=1e6;
using namespace std;
int a[105][105];
int aa[105][105];
int b[100005];
int c[100005];
int d[100005];
int e[100005];
int main()
{
    int n,m,ans1=0,ans2=0,ans3=0,ans4=0,j,k=INF;
    ios::sync_with_stdio(false);
    cin>>n>>m;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    for(int i=1; i<=n; i++)
        for( j=1; j<=m; j++)
        {
            cin>>a[i][j];
            aa[i][j]=a[i][j];
        }
    for(int i=1; i<=n; i++)
    {
        k=INF;
        for(j=1; j<=m; j++)
            k=min(k,a[i][j]);
        if(k==0)
            continue;
        else
        {
            for(j=1; j<=m; j++)
                a[i][j]-=k;
            for(j=1; j<=k; j++)
                b[++ans1]=i;
        }
    }

    for(int i=1; i<=m; i++)
    {
        k=INF;
        for(j=1; j<=n; j++)
            k=min(k,a[j][i]);
        if(k==0)
            continue;
        else
        {
            for(j=1; j<=n; j++)
                a[j][i]-=k;
            for(j=1; j<=k; j++)
                c[++ans2]=i;
        }
    }

    for(int i=1; i<=m; i++)
    {
        k=INF;
        for(j=1; j<=n; j++)
            k=min(k,aa[j][i]);
        if(k==0)
            continue;
        else
        {
            for(j=1; j<=n; j++)
                aa[j][i]-=k;
            for(j=1; j<=k; j++)
                e[++ans4]=i;
        }
    }

    for(int i=1; i<=n; i++)
    {
        k=INF;
        for(j=1; j<=m; j++)
            k=min(k,aa[i][j]);
        if(k==0)
            continue;
        else
        {
            for(j=1; j<=m; j++)
                aa[i][j]-=k;
            for(j=1; j<=k; j++)
                d[++ans3]=i;
        }
    }

    int dd=0;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            if(a[i][j]==0)
                dd++;
    if(dd!=m*n)
        cout<<"-1"<<endl;
    else
    {
        if(ans1+ans2<ans3+ans4)
        {
            cout<<ans1+ans2<<endl;
            for(int i=1; i<=ans1; i++)
                cout<<"row "<<b[i]<<endl;
            for(int i=1; i<=ans2; i++)
                cout<<"col "<<c[i]<<endl;
        }
        else
        {
             cout<<ans3+ans4<<endl;
            for(int i=1; i<=ans3; i++)
                cout<<"row "<<d[i]<<endl;
            for(int i=1; i<=ans4; i++)
                cout<<"col "<<e[i]<<endl;
        }

    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41700151/article/details/83097033