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

    Solutions


    A. Ichihime and Triangle

    直接让三边是(a,c,c)即可

    #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 a,b,c,d;
    		scanf("%d%d%d%d",&a,&b,&c,&d);
    		printf("%d %d %d
    ",a,c,c);
    	}	
    }
    

    B. Kana and Dragon Quest game

    贪心,只要操作1不会反向增加就一直用,然后再判断操作2能不能把血扣完。

    #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 x,n,m;
    		scanf("%d%d%d",&x,&n,&m);
    		if (x<=m*10) {
    			puts("YES");
    			continue;
    		}
    		while (n--) {
    			x=x/2+10;
    			if (x<=20) break;
    		}
    		if (x<=m*10) puts("YES");
    		else puts("NO");
    	}	
    }
    

    C. Linova and Kingdom

    我一直想标记出工业节点,然后也是根据深度和以它为根的子树大小来写的,我认为肯定是叶节点为工业节点,然后就不太好操作了,后来又尝试了先把靠近王国的节点变为旅游节点,深度相同先变子树小的节点。。

    后来看了正解,如果把一个节点(u)变为旅游节点,对应的贡献就是(size_u-dep_u),根据自己的(size,dep)含义灵活改变,减少的是节点(u)到1号节点经过的点,增加的是节点(u)子树的大小。然后排序,选前(n-k)大就可以了。

    #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 dep[2*N];
    vector<int> G[2*N];
    int n,k;
    int dd[2*N];
    int dfs(int u,int fa) {
    	dep[u]=dep[fa]+1;
    	for (auto it:G[u]) {
    		if (it!=fa) {
    			dd[u]+=dfs(it,u);
    		}
    	}
    	return dd[u]+1;
    }
    vector<int> t;
    int main() {
    	scanf("%d%d",&n,&k);
    	for (int i=1;i<n;i++) {
    		int u,v;
    		scanf("%d%d",&u,&v);
    		G[u].pb(v);
    		G[v].pb(u);
    	}
    	dfs(1,0);
    	for (int i=1;i<=n;i++) t.pb(dd[i]-(dep[i]-1));
    	sort(all(t));
    	ll sum=0;
    	for (int i=sz(t)-(n-k);i<sz(t);i++) sum+=t[i];
    	printf("%lld
    ",sum);
    }
    

    D. Xenia and Colorful Gems

    没有什么思路。

    假如(xleq yleq z),那么(x,z)尽量靠近(y)比较好一点。然后就可以固定其中一个,在另外两个里面二分。由于是假设的,所以要考虑多种情况。

    小于等于就是(upper\_bound-1),大于等于就直接(lower\_bound)
    这里需要把长度也传进来,不然没发对应长度。如果使用vector注意开的大小。

    #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 _;
    ll ans;
    ll r[N],g[N],b[N];
    ll sq(ll x) {return x*x;}
    void solve(ll r[],int nr,ll g[],int ng,ll b[],int nb) {
    	for (int i=0;i<nr;i++) {
    		ll x=r[i];
    		int y=lower_bound(g,g+ng,x)-g;
    		int z=upper_bound(b,b+nb,x)-b;
    		if (z==0||y==ng) continue;
    		z--; ans=min(ans,sq(x-g[y])+sq(x-b[z])+sq(g[y]-b[z]));
    	}
    }
    int main() {
    	for (scanf("%d",&_);_;_--) {
    		int nr,ng,nb;
    		scanf("%d%d%d",&nr,&ng,&nb);
    		for (int i=0;i<nr;i++) scanf("%lld",&r[i]);
    		for (int i=0;i<ng;i++) scanf("%lld",&g[i]);
    		for (int i=0;i<nb;i++) scanf("%lld",&b[i]);
    		sort(r,r+nr); sort(g,g+ng); sort(b,b+nb);
    		ans=INF;
    		solve(r,nr,g,ng,b,nb); solve(r,nr,b,nb,g,ng);
    		solve(g,ng,b,nb,r,nr); solve(g,ng,r,nr,b,nb);
    		solve(b,nb,r,nr,g,ng); solve(b,nb,g,ng,r,nr);
    		printf("%lld
    ",ans);
    	}	
    }
    
  • 相关阅读:
    ie下table无法设置宽度的坑,解决方案:在td里面添加div把td宽度撑开即可。
    js simple drag.
    javascript事件捕获机制,dom tree
    WPF,布局,Menu,MenuItem,DockPanel,Grid,DockPanel.Dock='',ToolBar,Content,Image,Uri
    .net IntPtr ==interoperable pointer
    Why do I keep getting mixed tabs and spaces in a Visual Studio C# code window?[vs power tools issue transfered]
    vs nuget package control.
    Introduction to the WinPcap Networking Libraries
    读懂这一篇,集群节点不下线
    函数组合的 N 种模式
  • 原文地址:https://www.cnblogs.com/ACMerszl/p/12730845.html
Copyright © 2011-2022 走看看