分析
: 思路:反向考虑其实就是,然后和分别和。很傻的题。
:思路很简单,贪心考虑,先找出最长的边,固定不动,其他边依据这条边进行修改,就是遵循能改上就改上,所以到这走肯定是最优选择,然后就是的实现了。
:开始我想,这不是睿智题吗,这不简单,奇数偶数完事了,然后特判一下。然后喜提。后来发现事情没那么简单,但是思考一下发现也不难,就是如果一定不可行,然后否则如果为质数,那么显然可以,如果不是质数,我们就要判断在~之间有没有的因子就行了。时间复杂度。
代码
:
#include <bits/stdc++.h>
using namespace std;
int t,n;
const int N=2e5+10;
int a[N],b[N];
void solve(){
cin>>n;
for(int i=1;i<=n-1;i++){
cin>>b[i];
}
if(n==2){
cout<<b[1]<<" "<<b[1]<<endl;
return;
}
else{
for(int i=1;i<=n-1;i++){
a[i+1]=min(b[i],b[i+1]);
}
a[1]=b[1],a[n]=b[n-1];
}
for(int i=1;i<=n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>t;
while(t--) solve();
return 0;
}
:
#include <bits/stdc++.h>
using namespace std;
const int M = 12, N = 1 << M;
int n, m, a[N], ans;
inline int dfs(int d, int x) {
if (d > m) return 0;
int lson = dfs(d + 1, x << 1), rson = dfs(d + 1, x << 1 | 1);
ans += abs((lson - rson) + (a[x << 1] - a[x << 1 | 1]));
return max(lson + a[x << 1], rson + a[x << 1 | 1]);
}
signed main(void) {
cin >> m; ++m; n = (1 << m) - 1;
for (int i = 2; i <= n; ++i) cin >> a[i];
dfs(1, 1);
cout << ans;
}
:
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);
#define ll long long
using namespace std;
int t;
const int N=1e6+10;
int primes[N];
bool st[N];
int cnt=0;
int f(int x){
int cnt=0;
st[1]=true;
for(int i=2;i<=x;i++){
if(!st[i]) primes[++cnt]=i;
for(int j=1;primes[j]<=x/i;j++){
st[primes[j]*i]=1;
if(i%primes[j]==0) break;
}
}
return cnt;
}
void solve(){
int n,m;
cin>>n>>m;
if(m==1){
cout<<"YES\n";
return;
}
else if(n==1){
cout<<"YES\n";
}
else if(n%2==0){
cout<<"NO\n";
}
else if(n<=m){
cout<<"NO\n";
}
else{
if(!st[n]){
cout<<"YES\n";
return;
}
for(int i=3;i<=sqrt(n);i++){
if(n%i==0 && i<=m){
cout<<"NO\n";
return ;
}
}
cout<<"YES\n";
}
}
int main(){
IOS;
//t=1;
f(N-5);
//for(int i=1;i<=100;i++) if(!st[i]) cout<<i<<endl;
cin>>t;
while(t--) solve();
return 0;
}