zoukankan      html  css  js  c++  java
  • Codeforces Round #481 (Div. 3) F. Mentors

    F. Mentors

    Example 1
    input
    4 2
    10 4 10 15
    1 2
    4 3
    output
    0 0 1 2 
    
    Example 2
    input
    10 4
    5 4 1 5 4 3 7 1 2 5
    4 6
    2 1
    10 8
    3 5
    output
    5 4 0 5 3 3 9 0 2 5 
    

    题目大意:

    每个程序员都有一个skill值,当一个skill高的程序员把skill低的程序员当作导师的时候会吵架,反之则不会,还有就是给定的k对程序员是会吵架的,现在让你计算每一个程序员可以收多少徒弟
    

      

    分析:

    创建一个struct node里面包含skill值和id(序号),然后对skill值进行排序,从前往后扫,计算出每一个id的可
    以收的徒弟数,然后在将输入的k对吵架的减去,注意这里减是有条件的,skill大的那一方的徒弟数减一,而skill
    小的那一方不用
    

      

    code:

    #define debug
    #include<bits/stdc++.h>
    #define pb push_back
    #define dbg(x) cout<<#x<<" = "<<(x)<<endl;
    #define lson l,m,rt<<1
    #define cmm(x) cout<<"("<<(x)<<")";
    #define rson m+1,r,rt<<1|1
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<ll,ll>PLL;
    typedef pair<int,ll>Pil;
    const ll INF = 0x3f3f3f3f;
    const ll inf=0x7fffffff;
    const double eps=1e-8;
    const int maxn =1e6+10;
    const int N = 510;
    const ll mod=1e9+7;
    const ll MOD=1e9;
    //------
    //define
    int idx[maxn];
    int res[maxn];
    struct node {
    	int x,id;
    	node(int x=0,int id=0):x(x),id(id) {}
    	bool operator <(const node &a)const {
    		return x==a.x?id<a.id:x<a.x;
    	}
    } a[maxn];
    //solve
    void solve() {
    	int n,k;
    	while(cin>>n>>k) {
    		for(int i=0; i<n; i++) {
    			int x;
    			cin>>x;
    			a[i+1]=node(x,i+1);
    		}
    		sort(a+1,a+n+1);
    		for(int i=0; i<n; i++) {
    			idx[a[i+1].id]=i+1;
    		}
    		res[a[1].id]=0;
    		for(int i=2; i<=n; i++) {
    			if(a[i].x>a[i-1].x)
    				res[a[i].id]=i-1;
    			else res[a[i].id]=res[a[i-1].id];
    		}
    		while(k--) {
    			int u,v;
    			cin>>u>>v;
    			u=idx[u];
    			v=idx[v];
    			if(a[u].x>a[v].x)
    				res[a[u].id]--;
    			if(a[v].x>a[u].x)
    				res[a[v].id]--;
    		}
    		for(int i=1; i<=n; i++) {
    			cout<<res[i]<<" ";
    		}
    		cout<<endl;
    	}
    }
    
    int main() {
    	ios_base::sync_with_stdio(false);
    #ifdef debug
    	freopen("in.txt", "r", stdin);
    //	freopen("out.txt","w",stdout);
    #endif
    	cin.tie(0);
    	cout.tie(0);
    	solve();
    	/*
    		#ifdef debug
    			fclose(stdin);
    			fclose(stdout);
    			system("out.txt");
    		#endif
    	*/
    	return 0;
    }
    

      

  • 相关阅读:
    K8S之traefik高级特性
    docker nginx-php容器镜像瘦身优化
    Dubbo-服务消费者初始化
    ThreadLocal 源码分析
    JVM 对象分配规则
    JVM GC 机制
    LockSupport
    自旋锁
    CAS
    Synchronized 监视器锁
  • 原文地址:https://www.cnblogs.com/visualVK/p/9038474.html
Copyright © 2011-2022 走看看