zoukankan      html  css  js  c++  java
  • Codeforces Goodbye2020部分题解

    Problem A

    问有多少不同面积的三角形,数据量较小,那么我们暴力扫过去丢set就好了。

    Problem B

    首先我扫完一边后一定是有些位置被站住了,那么根据桶排的思想,每个位置可能存在多个,那么这些多个我们要使它尽可能的多做贡献,就贪心的往后加,最后统计一共有多少位置就可以了。

    Problem C

    最少要多少次操作可以破环原串的回文性质,那么模拟可以发现,一个回文串只要超出了3,那么他肯定存在字串长度为2或者3的回文串,那么我们只要扫一遍并且在过程中破坏2和3的回文串就可以了。

    Problem D

    图论题面,其实是思维题,我们统计度数,然后每次在度数还允许的条件下加上点权,可以最优化答案。

    #include<bits/stdc++.h>
    using namespace std;
    typedef pair<int,int> PII;
    void check_max (int &a,int b) {a=max (a,b);}
    void check_min (int &a,int b) {a=min (a,b);}
    typedef long long ll;
    const int maxn=1e5+10;
    ll w[maxn];
    ll degree[maxn];
    ll v[maxn];
    vector <ll> ans;
    
    inline bool cmp (int x,int y) {
    	return x>y;
    }
    
    int main () {
    	int t; scanf ("%d",&t);
    	while (t--) {
    		int n; scanf ("%d",&n);
    		ll now=0;
    		ans.clear ();
    		for (int i=1;i<=n;i++) scanf ("%lld",&w[i]),now+=w[i];
    		for (int i=1;i<=n-1;i++) {
    			int x,y; scanf ("%d%d",&x,&y);
    			degree[x]++;
    			degree[y]++;
    		}
    		int cnt=0;
    		for (int i=1;i<=n;i++) 
    			for (int j=1;j<degree[i];j++) v[++cnt]=w[i];
    		sort (v+1,v+cnt+1,cmp);
    		for (int i=1;i<n;i++) printf ("%lld ",now),now+=v[i];
    		printf ("
    ");
    	}
    	return 0;
    }
    
  • 相关阅读:
    操作系统 进程(下)
    操作系统 进程(上)
    进程的执行状态
    操作系统之内存与进程
    阿里巴巴一道笔试题
    ASP.NET 验证码 不同浏览器 不刷新问题
    Android常用控件之GridView使用BaseAdapter
    spoj 8222 Substrings (后缀自动机)
    【每天一个Linux命令】13. Linux中whereis命令的用法
    JSP 文件上传下载系列之二[Commons fileUpload]
  • 原文地址:https://www.cnblogs.com/hhlya/p/14219875.html
Copyright © 2011-2022 走看看