题目来自于:George Plover.
很水的一次,各位见谅.
T1 有两个年轻人
题目分析
统计序列中 \(1\) 的个数即可.
点击查看代码
#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int t,n;
ll a[10005];
inline ll re(){
register ll k=0,f=1ll;
register char c=getchar();
while(!isdigit(c)){
if(c=='-') f=-1ll;
c=getchar();
}
while(isdigit(c)){
k=k*10ll+(c^48ll);
c=getchar();
}
return 1ll*k*f;
}
void wr(ll x){
if(x<0){
x=~x+1;
putchar('-');
}
if(x>9) wr(x/10ll);
putchar(x%10ll^48ll);
}
signed main(){
t=re();
while(t--){
n=re();
ll cnt=0;
for(int i=1;i<=n;++i){
a[i]=re();
if(a[i]==1) ++cnt;
}
if(cnt==n){
if(n&1)
puts("Yes");
else
puts("No");
}
else if(n-cnt&1){
if(cnt&1)
puts("No");
else
puts("Yes");
}
else{
if(cnt&1)
puts("No");
else
puts("Yes");
}
}
return 0;
}
T2 搬砖
题目分析
根据 \(N\) 的范围,容易想到状压 dp,不妨进行记忆化搜索. 我们先预处理各个点的距离,然后考虑一个点要么自己统计答案,要么与另一个点结合.
点击查看代码
#include <cmath>
#include <queue>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int n;
ll ans;
ll dis[25][25];
ll f[(1<<22)+10];
inline ll re(){
register ll k=0,f=1ll;
register char c=getchar();
while(!isdigit(c)){
if(c=='-') f=-1ll;
c=getchar();
}
while(isdigit(c)){
k=k*10ll+(c^48ll);
c=getchar();
}
return 1ll*k*f;
}
void wr(ll x){
if(x<0){
x=~x+1;
putchar('-');
}
if(x>9) wr(x/10ll);
putchar(x%10ll^48ll);
}
struct node{
int x,y;
}s[25];
inline ll dist(int i,int j){
return (s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y);
}
inline void inputbox(){
s[0].x=re(),s[0].y=re();
n=re();
for(int i=1;i<=n;++i) s[i].x=re(),s[i].y=re();
for(int i=0;i<n;++i)
for(int j=i+1;j<=n;++j)
dis[i][j]=dis[j][i]=dist(i,j);
ans=0x3f3f3f3f;
memset(f,0x3f3f3f3f,sizeof(f));
}
int a[25];
int num[25];
bool vis[25];
void dfs(int p,int res,int len,int s){
if(res>f[s]) return;
if(res>=ans) return;
if(vis[p]){
dfs(p+1,res,len,s);
return;
}
if(p>n){
ans=res;
for(int i=1;i<=n;++i) num[i]=a[i];
return;
}
a[len+1]=p;
dfs(p+1,res+dis[0][p]*2,len+1,s+(1<<p));
for(int i=p+1;i<=n;++i){
if(vis[i]) continue;
vis[i]=1;
a[len+2]=i;
int w=dis[0][p]+dis[p][i]+dis[i][0];
dfs(p+1,res+w,len+2,s+(1<<p)+(1<<i));
vis[i]=0;
}
f[s]=res;
return;
}
signed main(){
inputbox();
dfs(1,0,0,0);
wr(ans);
putchar('\n');
for(int i=1;i<n;++i){
wr(num[i]);
putchar(' ');
}
wr(num[n]);
return 0;
}
T3 闪电链
To be Continued.
标签:总结,20221004,return,10ll,int,ll,re,测试,include From: https://www.cnblogs.com/WXDreemurr/p/16754681.html