A.
题意:给出四个数 a b c d 要求从 a到b b到c c到d 选三个数构造三角形
思路:选b c c 就行 了 一定满足题意
B.
思路:贪心 一直使用第一种方法 然后在判断第二种方法能否将其杀死 记得特判单纯第二种方法就能杀死的情况 样例有给
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mes(x,a) memset(x,a,sizeof(x));
#define sca(a) scanf("%d",&a)
#define lowbit(x) x & (-x)
#define mk make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pii pair<int, int>
inline int read()
{
int x=0,flag_read=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
flag_read=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<3)+(x<<1)+c-'0';
c=getchar();
}
return x*flag_read;
}
const double eps=1e-9;
const double pi=acos(-1);
const int N = 1e6+5;
const int M = 1e7+5;
const int INF = 0x3f3f3f3f;
const int mod=2e6+5;
int main()
{
int t = read();
while( t-- )
{
int x,n,m;
x = read(),n = read() , m = read();
if(x <= m*10)
{
cout << "YES" << '\n';
continue;
}
while(n --)
{
int k = floor(x/2) + 10;
x = k;
}
if(x <= m*10)
cout << "YES";
else
cout << "NO" ;
cout << '\n';
}
return 0;
}
C.
题意:给出一颗树 以根结点为首都 其余结点为工业或者旅游结点 让你设定k个工业结点 使得其到首都的满意度最大 满意度为路过的旅游结点的个数
思路:树的问题dfs肯定没跑 首先我们贪心考虑 这个工业结点显然深度越大越好 其次 再考虑一个结点变成工业结点对结果的影响是什么 经过思考 我们得到如果当前点变成工业结点 那么这个点所在的子树上的结点到满意度都会-1 因为子树上的结点到根结点必定会经过该点 所以我们先dfs与处理每个点的深度 和 子树大小 然后根据深度 - 子树大小来排序 取前k大即可
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mes(x,a) memset(x,a,sizeof(x));
#define sca(a) scanf("%d",&a)
#define lowbit(x) x & (-x)
#define pb(x) push_back(x)
#define mk make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pii pair<int, int>
inline int read()
{
int x=0,flag_read=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
flag_read=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<3)+(x<<1)+c-'0';
c=getchar();
}
return x*flag_read;
}
const double eps=1e-9;
const double pi=acos(-1);
const int N = 2e5+5;
const int M = 1e7+5;
const int INF = 0x3f3f3f3f;
const int mod=2e6+5;
vector <int> e[N];
int sz[N],fa[N],dep[N];
void dfs(int u,int v)
{
dep[u] = dep[v] + 1;
sz[u] = 1;
for(int i = 0;i < e[u].size();i ++)
{
int to = e[u][i];
if(to == v)
continue;
dfs(to,u);
sz[u] += sz[to];
}
}
bool cmp(int x,int y)
{
return dep[x] - sz[x] > dep[y] - sz[y];
}
int main()
{
ios::sync_with_stdio(false);
int n , k;
cin >> n >> k;
for(int i = 1;i < n;i ++)
{
int u,v;
cin >> u >> v;
e[u].pb(v);
e[v].pb(u);
}
dfs(1,0);
for(int i = 1;i <= n;i ++)
fa[i] = i;
sort(fa + 1,fa + 1 + n,cmp);
LL res = 0;
for(int i = 1;i <= k;i ++)
res += (dep[fa[i]] - sz[fa[i]]);
cout << res << '\n';
return 0;
}
D.
题意:有三种宝石 从每种宝石里各挑一个 x,y,z 使得
最小
思路:当然是使得三个数越接近越好 枚举每种宝石 然后在其他两种里二分找最接近的 取最小值即可
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mes(x,a) memset(x,a,sizeof(x));
#define sca(a) scanf("%d",&a)
#define lowbit(x) x & (-x)
#define pb(x) push_back(x)
#define mk make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pii pair<int, int>
inline void read(int &x)
{
x=0;
int flag_read=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
flag_read=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<3)+(x<<1)+c-'0';
c=getchar();
}
}
const double eps=1e-9;
const double pi=acos(-1);
const int N = 1e5+5;
const int M = 1e7+5;
const int INF = 0x3f3f3f3f;
const int mod=2e6+5;
LL a[N],b[N],c[N];
LL cal(LL a,LL b,LL c)
{
return (a - b)*(a - b) + (b - c) * (b - c) + (a - c) * (a - c);
}
int main()
{
int t ;
scanf("%d",&t);
while(t --)
{
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i = 0; i < n; i ++)
scanf("%lld",&a[i]);
for(int i = 0; i < m; i ++)
scanf("%lld",&b[i]);
for(int i = 0; i < k; i ++)
scanf("%lld",&c[i]);
LL res = 2e18 + 5;
/*
均考虑三种情况
b >= a c >= a
b >= a c < a
b < a c > a
*/
sort(a, a + n);
sort(b, b + m);
sort(c, c + k);
for(int i = 0; i < n; i ++)
{
int x = lower_bound(b,b + m,a[i]) - b;
int y = lower_bound(c,c + k,a[i]) - c;
if(x == m)
x -- ;
if(y == k)
y -- ;
res = min(res,cal(a[i],b[x],c[y]));
if(x > 0)
res = min(res,cal(a[i],b[x - 1],c[y]));
if(y > 0)
res = min(res,cal(a[i],b[x],c[y - 1]));
}
for(int i = 0; i < m; i ++)
{
int x = lower_bound(a,a + n,b[i]) - a;
int y = lower_bound(c,c + k,b[i]) - c;
if(x == n)
x -- ;
if(y == k)
y -- ;
res = min(res,cal(a[x],b[i],c[y]));
if(x > 0)
res = min(res,cal(a[x - 1],b[i],c[y]));
if(y > 0)
res = min(res,cal(a[x],b[i],c[y - 1]));
}
for(int i = 0; i < k; i ++)
{
int x = lower_bound(a,a + n,c[i]) - a;
int y = lower_bound(b,b + m,c[i]) - b;
if(x == n)
x -- ;
if(y == m)
y -- ;
res = min(res,cal(a[x],b[y],c[i]));
if(x > 0)
res = min(res,cal(a[x - 1],b[y],c[i]));
if(y > 0)
res = min(res,cal(a[x],b[y - 1],c[i]));
}
printf("%lld\n",res);
}
return 0;
}