2015 ACM/ICPC亚洲区长春站 【5/13】


A : Too Rich

DFS: 戳我看题解


F : Almost Sorted Array

最长上升子序列


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef long long ll;
const int maxn = 100005;
const ll mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;

int n;
int a[maxn];
int temp[maxn];

int main()
{
    rush()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        int Max=1;
        mst(temp,0x3f);
        temp[0]=-1;
        for(int i=1;i<=n;i++)
        {
            int pos=upper_bound(temp,temp+n,a[i])-temp;
            temp[pos]=a[i];
            Max=max(Max,pos);
        }
        mst(temp,0x3f);
        temp[0]=-1;
        reverse(a+1,a+n+1);
        for(int i=1;i<=n;i++)
        {
            int pos=upper_bound(temp,temp+n,a[i])-temp;
            temp[pos]=a[i];
            Max=max(Max,pos);
        }
        if(Max>=n-1) puts("YES");
        else puts("NO");
    }
    return 0;
}


G :Dancing Stars on Me

正多边形的判断。

有一个结论,顶点都在格点上的正多边形只能是正方形。


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef long long ll;
const int maxn = 105;
const ll mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;

struct node
{
    int x,y;
}a[maxn];

int getdis(node a,node b)
{
    return (b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y);
}

int temp[maxn];

int main()
{
    int n;
    rush()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&a[i].x,&a[i].y);
        }
        if(n!=4)
        {
            puts("NO");
            continue;
        }
        int cnt=0;
        for(int i=1;i<=4;i++)
        for(int j=i+1;j<=4;j++)
        {
            temp[cnt++]=getdis(a[i],a[j]);
        }
        sort(temp,temp+6);
        if(temp[0]==temp[3]&&temp[3]!=temp[4]&&temp[4]==temp[5])
        {
            puts("YES");
        }
        else puts("NO");
    }
    return 0;
}


H : Partial Tree

背包:戳我看题解


J : Chip Factory

01字典树:戳我看题解


L : House Building

给出一个组合体,计算其表面积(底面积不算)。

爆搜出重叠部分面积即可。


#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <map>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef long long ll;
const int maxn = 55;
const ll mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;


int mp[maxn][maxn][1005];
int num[maxn][maxn];

int solve(int x,int y,int z)
{
    int ans=0;
    if(mp[x-1][y][z])  ans++;
    if(mp[x+1][y][z])  ans++;
    if(mp[x][y-1][z])  ans++;
    if(mp[x][y+1][z])  ans++;
    if(mp[x][y][z+1])   ans++;
    return ans;
}

int main()
{
    int n,m;
    rush()
    {
        scanf("%d%d",&n,&m);
        int sum=0;
        int cnt=0;
        int x;
        int Max=0;
        mst(mp,0);
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                scanf("%d",&x);
                Max=max(Max,x);
                num[i][j]=x;
                sum+=x;
                for(int k=1;k<=x;k++)
                {
                    mp[i][j][k]=1;
                }
            }
        }
        for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        for(int k=1;k<=num[i][j];k++)
        {
            if(mp[i][j][k]==0) continue;
            cnt+=solve(i,j,k);
            //printf("%d\n",solve(i,j,k));
        }
        int ans=sum*5-cnt;
        printf("%d\n",ans);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值