当前位置: 代码迷 >> 综合 >> A. Phoenix and Gold
  详细解决方案

A. Phoenix and Gold

热度:65   发布时间:2023-11-22 08:47:02.0

题目

#include<bits/stdc++.h>
#define INF 0x3f3f3f
#define mod 1000000007
#define PI 3.14159265358979323846
#define Base 23333333
#define eps 0.000001
#define int long long
#define mst(x) memset(x,0,sizeof(x))
#define range(x,y) 1
#define baoliu(x,y) cout<<fixed<<setprecision(y)<<x
using namespace std;
/*最大公约数*/inline int gcd(int a, int b) {
     return b > 0 ? gcd(b, a%b) : a; }
/*最小公倍数*/inline int lcm(int a, int b) {
     return a * b / gcd(a, b); }
/*平方数*/inline int qpow(int a, int n) {
     int ans = 1;    while (n) {
     if (n & 1) {
     ans *= a; }a *= a; n >>= 1; }return ans; }
/*平方数(结果除模)**/inline int _qpow(int a, int n) {
     int ans = 1; while (n) {
     if (n & 1) {
     ans *= a % mod;    ans %= mod; }a *= a; a %= mod; n >>= 1; }return ans % mod; }
///*快读 */inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch<'0' || ch>'9') { if (ch == '-') { f = -1; } ch = getchar(); } while (ch >= '0'&&ch <= '9') { x = 10 * x + ch - '0'; ch = getchar(); } return x * f; }const int maxn = 2e5 + 5;
int a[maxn];
signed main()
{
    int t;cin>>t;while(t--){
    mst(a);int n,m;cin>>n>>m;for(int i=1;i<=n;i++){
    cin>>a[i];}sort(a+1,a+1+n);reverse(a+1,a+1+n);int sum=0;int flag=0;for(int j=1;j<=n;j++){
    sum+=a[j];if(sum==m&&j==n){
    flag=1;}else if(sum==m){
    swap(a[j],a[j+1]);}}if(flag) cout<<"NO"<<endl;else if(!flag){
    cout<<"YES"<<endl;for(int j=1;j<=n;j++)cout<<a[j]<<" ";cout<<endl;}}return 0;
}
#include <bits/stdc++.h>
using namespace std;bool IsSquare(long long int a){
    //判断能否开平方long long int b=sqrt(a);if(b*b==a){
    return true;}else{
    return false;}
}int main(){
    int t;cin>>t;for(int i=0;i<t;i++){
    long long int n;cin>>n;
/*两种组合情况*/        if(n%2==0 && IsSquare(n/2)){
    cout<<"YES"<<endl;}else if(n%4==0 && IsSquare(n/4)){
    cout<<"YES"<<endl;}else{
    cout<<"NO"<<endl;}}
}