Fork me on GitHub

2014 UESTC 暑前集训队内赛(3) 部分解题报告

B.Battle for Silver

定理:完全图Kn是平面图当且仅当顶点数n<=4.

枚举所有完全图K1,K2,K3,K4,找出最大总权重。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 100000000

int mp[500][500];
int w[500];

int main()
{
    int n,m;
    int i,j,k,h;
    int x,y;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(mp,0,sizeof(mp));
        int maxi = 0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&w[i]);
            maxi = max(maxi,w[i]);
        }
        for(i=1;i<=m;i++)
        {
            scanf("%d%d",&x,&y);
            mp[x][y] = mp[y][x] = 1;
            maxi = max(maxi,w[x]+w[y]);
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<i;j++)
            {
                for(k=1;k<j;k++)
                {
                    if(mp[i][j] && mp[i][k] && mp[j][k])
                    {
                        maxi = max(maxi,w[i] + w[j] + w[k]);
                    }
                    else
                        continue;
                    for(h=1;h<k;h++)
                    {
                        if(mp[h][i] && mp[h][j] && mp[h][k])
                            maxi = max(maxi,w[i]+w[j]+w[k]+w[h]);
                    }
                }
            }
        }
        printf("%d\n",maxi);
    }
    return 0;
}
View Code

 

F.First Date

日历题。两个日历有一个初始的对应关系,然后根据这个信息递推,因为闰年计算方式的不同,来得出新的对应关系,暴力枚举1582-10-04(Julian)~9999-12-31(Gregorian)为止,做一个哈希关系存储,最多为(10000-1582)*12*31,约为3131496,不会爆内存。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 100000000

struct node
{
    int y,m,d;
    node(int Y,int M,int D)
    {
        y = Y;
        m = M;
        d = D;
    }
    node(){}
};

int mp[4000000];

int HS(node ka)
{
    int res = (ka.y*12+ka.m-1)*31+ka.d-1;
    return res;
}

int JuLeap(int Y)
{
    if(Y%4 == 0)
        return 1;
    return 0;
}

int GreLeap(int Y)
{
    if((Y%4 == 0 && Y%100 != 0) || (Y%400 == 0))
        return 1;
    return 0;
}

int month_day(int Y,int M,int flag)
{
    if(M == 4 || M == 6 || M == 9 || M == 11)
        return 30;
    else if(M != 2)
        return 31;
    else if(flag)
    {
        if(JuLeap(Y))
            return 29;
        else
            return 28;
    }
    else if(!flag)
    {
        if(GreLeap(Y))
            return 29;
        else
            return 28;
    }
}

node add(node ka,int flag)
{
    node kb = ka;
    if(ka.d+1 > month_day(ka.y,ka.m,flag))
    {
        if(ka.m+1 > 12)
        {
            kb.y = ka.y+1;
            kb.m = 1;
            kb.d = 1;
        }
        else
        {
            kb.m = ka.m+1;
            kb.d = 1;
        }
    }
    else
        kb.d = ka.d + 1;
    return kb;
}

void DOIT()
{
    node ka = node(1582,10,4);
    node kb = node(1582,10,15);
    mp[HS(ka)] = HS(kb);
    int y,m,d;
    while(kb.y <= 9999)
    {
        ka = add(ka,1);
        kb = add(kb,0);
        mp[HS(ka)] = HS(kb);
    }
}

int main()
{
    int Y,M,D;
    DOIT();
    while(scanf("%d-%d-%d",&Y,&M,&D)!=EOF)
    {
        node S = node(Y,M,D);
        int E = mp[HS(S)];
        int day = E%31+1;
        E/=31;
        int month = E%12+1;
        E/=12;
        int year = E;
        printf("%04d-%02d-%02d\n",year,month,day);
    }
    return 0;
}
View Code

 

G.Grachten

超级大水题。不说了。

 

(没做出来的以后持续更新)

posted @ 2014-05-25 22:23  whatbeg  阅读(253)  评论(0编辑  收藏  举报