Codeforces Round #190 (Div. 2) 总结

这场cf做的有点伤,比赛最后过了D题,四题,就算过三题也有希望变紫色的,回到寝室居然挂了两题。。。比赛的时候前三题做的速度还是可以的,可惜B题wa了,后来弄了很久才弄出特殊情况过了,C题感觉就很简单的模拟题,不过写起来貌似写得不细心,赛后加了一句话就过了。D题光知道贪心两种情况了,居然把两种情况弄成一种交上去,还过了pretest。。。如果不过的话,可能还能改出来,下次再战,最近好好练!


A题:

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define LL __int64
#define max(a,b)  (a>b?a:b)
#define min(a,b)  (a>b?b:a)
#define lowbit(x) ((x)&(-x))
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r

int main()
{
    int n,m,i;
    scanf("%d%d", &n, &m);
    printf("%d\n", n+m-1);
    for(i = 1;i <= m; i++)
        printf("1 %d\n", i);
    for(i = 2;i <= n; i++)
        printf("%d 1\n", i);
    return 0;
}
B题:

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define LL __int64
#define max(a,b)  (a>b?a:b)
#define min(a,b)  (a>b?b:a)
#define lowbit(x) ((x)&(-x))
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r

int main()
{
    int i,j,r,g,b;
    scanf("%d%d%d", &r, &g, &b);
    LL x = r/3+g/3+b/3+min(min(r%3,g%3),b%3);
    LL y = min(min(r,g),b);
    y += (r-y)/3+(g-y)/3+(b-y)/3;
    x = max(x,y);
    if(r%3==2 && g%3==2)
    {
        if(b > 1)
            x = max(b/3-1+r/3+g/3+2,x);
     }
     if(r%3==2 && b%3==2)
    {
        if(g > 1)
            x = max(g/3-1+r/3+b/3+2,x);
     }
     if(b%3==2 && g%3==2)
    {
        if(r > 1)
            x = max(r/3-1+b/3+g/3+2,x);
     }
    printf("%I64d\n", x);
    return 0;
}

C题:
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define LL __int64
#define max(a,b)  (a>b?a:b)
#define min(a,b)  (a>b?b:a)
#define lowbit(x) ((x)&(-x))
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r

char s[1111];
int main()
{
    int a,b,i,x,y,sx,sy;
    scanf("%d%d", &a, &b);
    scanf("%s",  s);
    if(a == 0 && b == 0)
        return puts("Yes") , 0;
    int len = strlen(s);
    x = 0;y = 0;
    for(i = 0;i < len; i++)
    {
        if(s[i] == 'U'){
            y++;
        }
        else if(s[i] == 'D'){
            y--;
        }
        else if(s[i] == 'L'){
            x--;
        }
        else{
            x++;
        }
        if(x == a && y == b)
            return puts("Yes") , 0;
    }
    sx = 0;
    sy = 0;
    for(i = 0;i < len; i++)
    {
        if(x == sx){
            if(y == sy){
                if(x == a && y == b)
                    return puts("Yes") , 0;
            }   
            else{
                if((b-sy)%(y-sy) == 0 && (b-sy)/(y-sy)>0 && sx==a)
                    return puts("Yes") , 0;
            }
        }
        else if(y == sy){
            if((a-sx)%(x-sx) == 0 && (a-sx)/(x-sx) > 0)
                return puts("Yes") , 0;
        }
        else{
            if((a-sx)%(x-sx) == 0 && (b-sy)%(y-sy) == 0 && (a-sx)/(x-sx) == (b-sy)/(y-sy) && (a-sx)/(x-sx)>0)
                return puts("Yes") , 0;
        }
        if(s[i] == 'U'){
            y++;
            sy++;
        }
        else if(s[i] == 'D'){
            y--;
            sy--;
        }
        else if(s[i] == 'L'){
            x--;
            sx--;
        }
        else{
            x++;
            sx++;
        }
        if(x == sx){
            if(y == sy){
                if(x == a && y == b)
                    return puts("Yes") , 0;
            }   
            else{
                if((b-sy)%(y-sy) == 0 && (b-sy)/(y-sy)>0 && x==a)
                    return puts("Yes") , 0;
            }
        }
        else if(y == sy){
            if((a-sx)%(x-sx) == 0 && (a-sx)/(x-sx) > 0)
                return puts("Yes") , 0;
        }
        else{
            if((a-sx)%(x-sx) == 0 && (b-sy)%(y-sy) == 0 && (a-sx)/(x-sx) == (b-sy)/(y-sy) && (a-sx)/(x-sx)>0)
                return puts("Yes") , 0;
        }
    }
    puts("No");
    return 0;
}
D题:
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define LL __int64
#define max(a,b)  (a>b?a:b)
#define min(a,b)  (a>b?b:a)
#define lowbit(x) ((x)&(-x))
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r

bool vis[1111];
int c[1111];
struct PP{
    char s[11];
    int len;
}a[111];
bool cmp(PP a,PP b){
    return a.len < b.len;
}
bool cmp2(PP a,PP b){
    return a.len > b.len;
}
bool cmp1(int a,int b){
    return a > b;
}
int main()
{
    int n,m,i,j;
    scanf("%d%d", &n, &m);
    for(i = 0;i < n; i++)
        scanf("%s%d", a[i].s, &a[i].len);
    for(i = 0;i < m; i++)
        scanf("%d", &c[i]);
    sort(c,c+m,cmp1);
    sort(a,a+n,cmp);
    memset(vis,0,sizeof(vis));
    int sum = 0;
    int ans1 = 0;
    for(i = 0 ;i < n; i++)
    {
        if(a[i].s[0] == 'A')
        {
            for(j = 0;j < m; j++)
                if(!vis[j] && c[j] >= a[i].len)
                {
                    sum++;
                    vis[j] = 1;
                    ans1 += c[j] - a[i].len;
                    break;
                }
        }
    }
    sort(a,a+n,cmp2);
    sort(c,c+m);
    memset(vis,0,sizeof(vis));
    int ans2 = 0;
    for(i = 0;i < n; i++)
    {
        if(a[i].s[0] == 'D')
        {
            for(j = 0;j < m; j++)
                if(!vis[j] && c[j] > a[i].len)
                {
                    sum++;
                    vis[j] = 1;
                    break;
                }
            if(j == m)
                break;
        }
    }
    if(i == n)
    {
        for(i = 0;i < n; i++){
            if(a[i].s[0] == 'A'){
                for(j = 0;j < m; j++)
                    if(!vis[j] && c[j] >= a[i].len){
                        sum++;
                        vis[j] = 1;
                        ans2 += c[j]-a[i].len;
                        break;
                    }
                if(j == m)
                    break;
            }
        }
        if(i == n){
            for(i = 0;i < m ;i++)
                if(!vis[i])
                    ans2 += c[i];
        }
        printf("%d\n", max(ans1,ans2));
    }
    else
        printf("%d\n", ans1);
    return 0;
}

你可能感兴趣的:(ACM_Codeforces)