zoukankan      html  css  js  c++  java
  • Codeforces Round #633 (Div. 2)

    Solutions


    A. Filling Diamonds

    通过猜测就欧克了。
    发现如果竖直放置就只有一种摆放方法了。

    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define mp make_pair
    #define all(x) (x).begin(), (x).end()
    #define fi first
    #define se second
    #define sz(x) ((int)(x).size())
    typedef vector<int> VI;
    typedef pair<int,int> PII;
    const int N=100010;
    const int inf=0X3f3f3f3f;
    const long long INF=0x3f3f3f3f3f3f3f3f;
    const double eps=1e-6;
    const double pi=acos(-1.0);
    const int mod=1000000007;
    typedef long long ll;
    ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
    // head
    int _;
    int main() {
    	for (scanf("%d",&_);_;_--) {
    		int n;
    		scanf("%d",&n);
    		printf("%d
    ",n);
    	}
    }
    

    B. Sorted Adjacent Differences

    排序后,比较显然的就相距最远的放右边,然后就这样放就可以了。

    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define mp make_pair
    #define all(x) (x).begin(), (x).end()
    #define fi first
    #define se second
    #define sz(x) ((int)(x).size())
    typedef vector<int> VI;
    typedef pair<int,int> PII;
    const int N=100010;
    const int inf=0X3f3f3f3f;
    const long long INF=0x3f3f3f3f3f3f3f3f;
    const double eps=1e-6;
    const double pi=acos(-1.0);
    const int mod=1000000007;
    typedef long long ll;
    ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
    // head
    int _;
    int main() {
    	for (scanf("%d",&_);_;_--) {
    		int n;
    		scanf("%d",&n);
    		VI t(n);
    		for (int i=0;i<n;i++) scanf("%d",&t[i]);
    		sort(all(t));
    		int l,r;
    		if (sz(t)&1) {
    			printf("%d ",t[sz(t)/2]);
    			l=sz(t)/2-1; r=sz(t)/2+1;
    		} else {
    			l=sz(t)/2-1; r=sz(t)/2; 
    		}
    		while (l>=0) {
    			printf("%d %d ",t[r++],t[l--]);
    		}
    		puts("");
    	}
    }
    

    C. Powered Addition

    这个题稍加分析,可以发现,你只要确定逆序的最大差值即可,然后计算秒数,这样的话,任意位置总是可以满足要求的。

    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define mp make_pair
    #define all(x) (x).begin(), (x).end()
    #define fi first
    #define se second
    #define sz(x) ((int)(x).size())
    typedef vector<int> VI;
    typedef pair<int,int> PII;
    const int N=100010;
    const int inf=0X3f3f3f3f;
    const long long INF=0x3f3f3f3f3f3f3f3f;
    const double eps=1e-6;
    const double pi=acos(-1.0);
    const int mod=1000000007;
    typedef long long ll;
    ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
    // head
    int _;
    int main() {
    	for (scanf("%d",&_);_;_--) {
    		int n;
    		scanf("%d",&n);
    		VI a(n),d(n);
    		for (int i=0;i<n;i++) scanf("%d",&a[i]);
    		d[0]=0;
    		int maxx=a[0];
    		for (int i=1;i<n;i++) {
    			if (a[i]<maxx) {
    				d[i]=maxx-a[i];
    			} else {
    				maxx=a[i];
    				d[i]=0;
    			}		
    		}
    		int sum=*max_element(all(d));
    		//printf("%d**
    ",sum);
    		if (sum==0) puts("0");
    		else {
    			int cnt=0;
    			ll tmp=1;
    			do {
    				sum-=tmp;
    				cnt++;
    				tmp<<=1;
    			} while (sum>0);
    			printf("%d
    ",cnt);
    		}
    	}
    }
    

    D. Edge Weight Assignment

    这道题分析了挺久的,如果路径都是偶数,那么最小肯定是1,如果存在奇数的话,最小肯定是3。接下来就是最大的情况了,我一开始以为和直径有关,后来发现越来越离谱。只需要统计非叶子节点连接多少个叶子节点即可,这些边的边权都要一致才可以,然后就解决了。这样就是纯属猜测了。

    正解就是通过一种方法可以最大化结果,然后就可以知道上述猜测的正确性了。也就是在图中非叶子节点上又多了叶子,那么就要和原来的那个叶子的边权一致。见官方图

    QQ截图20200430215221.jpg

    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define mp make_pair
    #define all(x) (x).begin(), (x).end()
    #define fi first
    #define se second
    #define sz(x) ((int)(x).size())
    typedef vector<int> VI;
    typedef pair<int,int> PII;
    const int N=100010;
    const int inf=0X3f3f3f3f;
    const long long INF=0x3f3f3f3f3f3f3f3f;
    const double eps=1e-6;
    const double pi=acos(-1.0);
    const int mod=1000000007;
    typedef long long ll;
    ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
    ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
    // head
    int n;
    vector<int> G[N];
    bool isleaf[N];
    int dep[N];
    bool flag;
    void dfs(int u,int p) {
    	dep[u]=dep[p]+1;
    	for (auto it:G[u]) {
    		if (it!=p) {
    			dfs(it,u);
    		}
    	}
    }
    int main() {
    	scanf("%d",&n);
    	for (int i=0;i<n-1;i++) {
    		int u,v;
    		scanf("%d%d",&u,&v);
    		G[u].pb(v);
    		G[v].pb(u);
    	}
    	int root;
    	for (int i=1;i<=n;i++) {
    		if (sz(G[i])==1) {
    			//printf("%d**
    ",i);
    			root=i;
    			isleaf[i]=true;
    		}
    	}
    	dep[0]=-1;
    	dfs(root,0);
    	int tot=0;
    	for (int i=1;i<=n;i++) {
    		//printf("%d#####
    ",dep[i]);
    		if (isleaf[i]) {
    			if (dep[i]&1) flag=true;
    		} else {
    			int num=0;
    			for (auto it:G[i]) {
    				if (sz(G[it])==1) num++;
    			}
    			if (num) num-=1;
    			tot+=num;
    		}
    	}
    	if (!flag) printf("1 ");
    	else printf("3 ");
    	printf("%d",n-1-tot);
    }
    
  • 相关阅读:
    浅谈三层模式
    javascript的全局变量
    BZOJ 3668 NOI2014 起床困难综合症 贪心
    调试经验--图像
    Mac OS X 10.10 执行 Eclipse 提示须要安装 Java
    ubuntuOS
    BLOB存储图片文件二进制数据是非对错
    API经济产业
    python模块目录文件后续
    MongoDB命令
  • 原文地址:https://www.cnblogs.com/ACMerszl/p/12811410.html
Copyright © 2011-2022 走看看