A : Too Rich
DFS: 戳我看题解
最长上升子序列
#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;
}
正多边形的判断。
有一个结论,顶点都在格点上的正多边形只能是正方形。
#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;
}