codeforces 785

A  直接模拟 开2个数组存一下  这样块

#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

#define MAXN 510
#define inf  1000000000

int x[10]={4,6,8,12,20};
char z[10][20]={"Tetrahedron","Cube","Octahedron","Dodecahedron","Icosahedron"};
int main()
{
    int n;
    int ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        char s[15];
        scanf("%s",s);
        for(int j=0;j<5;j++)
        {
            if(strcmp(s,z[j])==0)
            {
                ans += x[j];
            }
        }
    }
    printf("%d
",ans);
    return 0;
}
View Code

B 一个小朋友要从n个课调一节  m个里头调一节

要求是2节课之间间隔最长  否则0  不能 认为 a一定在前面  哈哈哈  GG了

输出时间间隔

#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

#define MAXN 510
#define inf  1000000000

int x[10]={4,6,8,12,20};
char z[10][20]={"Tetrahedron","Cube","Octahedron","Dodecahedron","Icosahedron"};
long long min(long long a,long long b)
{
    return a<b?a:b;
}
long long max(long long a,long long b)
{
    return a>b?a:b;
}
int main()
{
    int n,m;
    int l,r,l2,r2;
    l=inf;
    l2=inf;
    r=-inf;
    r2=-inf;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int l1,r1;
        scanf("%ld%ld",&l1,&r1);
        l=min(l,r1);
        r2=max(r2,l1);
    }
    scanf("%d",&m);
    for(int i=1;i<=m;i++)
    {
        int l1,r1;
        scanf("%d%d",&l1,&r1);
        r=max(l1,r);
        l2=min(l2,r1);
    }
    int ans = max(r-l,r2-l2);
    ans = max(ans,0);
    printf("%d
",ans);
    return 0;
}
View Code

C 有一个谷仓 里面有 n个米  然后每天都会来 m个米

超过n 就是n   有一个蚂蚁 第一天吃 1  第二天吃 2  ... 吃到没有 问  要多少天

这东西 显然是二分  最外面那个m>=n 的坑没想到  二分细节出问题了  二分上界GG了  lld  我操 

#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

#define LL   __int64
#define MAXN 510
#define inf  2000000010


int main()
{
    LL n,m;
    scanf("%I64d%I64d",&n,&m);
    if(m>=n)
    {
        printf("%lld
",n);
        return 0;
    }
    LL l,r;
    l=1;
    r=inf;
    LL ans=inf;
    while(l<=r)
    {
        LL day=(l+r)>>1;

        if(n-m>day*(day+1)/2)
            l=day+1;
        else
        {
            r=day-1;
            ans = min(ans,day);
        }
    }
    printf("%lld
",ans+m);
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/cherryMJY/p/6568375.html