zoukankan      html  css  js  c++  java
  • 「日常训练」School Marks(Codeforces Round 301 Div.2 B)

    题意与分析(CodeForces 540B)

    题意大概是这样的,有一个考试鬼才能够随心所欲的控制自己的考试分数,但是有两个限制,第一总分不能超过一个数,不然就会被班里学生群嘲;第二分数的中位数(科目数保证为奇数)不能低于某个数,不然他妈就不让他打游戏。已知(n)门中(k)门成绩,求符合条件的其他科目的成绩。注意,不能考0分
    乍一看就是一个简单的贪心问题。但是细节相对较多。
    抓住主要方向。先统计有多少门考不过中位数的,如果大于一半直接-1;然后按照这样的决策就可以了:小于一半的考1分,大于一半的考(y)分。如果剩余的分数配给做不到输出-1。

    代码

    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #define MP make_pair
    #define PB push_back
    #define fi first
    #define se second
    #define ZERO(x) memset((x), 0, sizeof(x))
    #define ALL(x) (x).begin(),(x).end()
    #define rep(i, a, b) for (int i = (a); i <= (b); ++i)
    #define per(i, a, b) for (int i = (a); i >= (b); --i)
    #define QUICKIO                  
        ios::sync_with_stdio(false); 
        cin.tie(0);                  
        cout.tie(0);
    using namespace std;
    
    int main()
    {
    	int n,k,p,x,y; cin>>n>>k>>p>>x>>y;
    	int nowtot=0,belowycnt=0;
    	int arr[1005]; rep(i,1,k) { cin>>arr[i]; nowtot+=arr[i]; if(arr[i]<y) belowycnt++; }
    	int restmark=x-nowtot;
    	if(nowtot+n-k>x || belowycnt>n/2) cout<<-1<<endl;
    	else
    	{
    		int geycnt=k-belowycnt;
    		vector<int> vec;
    		rep(i,k+1,n)
    		{
    			if(belowycnt<n/2)
    			{
    				restmark--;
    				if(restmark>=0)
    					{ vec.PB(1); belowycnt++; }
    			}
    			else
    			{
    				restmark-=y;
    				if(restmark>=0)
    					vec.PB(y);
    			}
    			if(restmark<=0) break;
    		}
    		if(vec.size()==n-k)
    		{
    			for(auto it:vec) cout<<it<<" ";
    			cout<<endl;
    		}
    		else cout<<-1<<endl;
    	}
    
    	
    	return 0;
    }
    
    
    如非注明,原创内容遵循GFDLv1.3发布;其中的代码遵循GPLv3发布。
  • 相关阅读:
    为什么我们不要 .NET 程序员
    Jquery异步请求数据实例代码
    关系数据库中表的基本属性有哪些
    利用VC从DLL传递消息到EXE
    新实体与原实体之间为一对多关系
    本人C++ Builder开发的仿Windows桌面应用程序源码
    delphi窗体动态设计 在系统运行时动态更改控件属性
    DB.ASP 用Javascript写ASP很灵活很好用很easy
    CrazyScan Satellite scan software 卫星扫描
    delphi中窗体半透明效果如何实现
  • 原文地址:https://www.cnblogs.com/samhx/p/cfr301d2b.html
Copyright © 2011-2022 走看看