zoukankan      html  css  js  c++  java
  • CF161B Discounts

    3 2
    2 1
    3 2
    3 1
    
    5.5
    2 1 2
    1 3
    
    4 3
    4 1
    1 2
    2 2
    3 2
    
    8.0
    1 1
    2 4 2
    1 3
    

    按照大小排下序,你会发现,如果按照从大到小的顺序,那么给凳子打折一定是最优的

    于是,我们就可以找凳子打折,最后无论剩下多少都撂倒最后一个购物车里

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #define maxn 1200
    #define rep(x,y,z) for(int x = y ; x <= z ; x ++)
    using namespace std ;
    struct dy{
    	int c , t , id ;
    }a[maxn] ;
    int n , m , l , pos , num , sum , res , g[maxn] , s[maxn] , ans[maxn][maxn] , k;
    bool book[maxn] ;
    double money ;
    int cmp(dy x , dy y) {
    	return x.c > y.c ;
    }  
    int main() {
    	scanf("%d%d",&n,&k) ;
    	rep(i,1,n) {
    		a[i].id = i ;
    		scanf("%d%d",&a[i].c,&a[i].t) ;
    		if(a[i].t == 1) res ++ ;
    	}sort(a+1,a+1+n,cmp) ;
    	rep(i,1,n) {
    		if(k > 1 && a[i].t == 1) {
    			k -- ;
    			res -- ;
    			book[i] = 1 ;
    			ans[++num][++s[num]] = a[i].id ;
    			money += 0.5*double(a[i].c) ;
    			if(!res) break ;
    		}
    	}
    	if(res) {
    		rep(i,1,n) {
    			if(book[i]) continue ;
    			pos = i ;
    			g[++sum] = a[i].id ;
    			money += double(a[i].c) ;
    		}
    		money -= 0.5*double(a[pos].c) ;
    	}else {
    		rep(i,1,n) {
    			if(book[i]) continue ;
    			if(k > 1) {
    				k -- ;
    				ans[++num][++s[num]] = a[i].id ;
    				money += double(a[i].c) ;
    			}else {
    				g[++sum] = a[i].id ;
    				money += double(a[i].c) ;
    			}
    		}
    	}
    	printf("%.1lf
    ",money) ;
    	rep(i,1,num) {
    		printf("%d ",s[i]) ;
    		rep(j,1,s[i]-1) {
    			printf("%d ",ans[i][j]) ;
    		}printf("%d
    ",ans[i][s[i]]) ;
    	}
    	if(!sum) return 0 ;
    	printf("%d " , sum ) ;
    	rep(i,1,sum-1) {
    		printf("%d ",g[i]) ;
    	}printf("%d
    ",g[sum]) ;
    	return 0 ;
    }
    
  • 相关阅读:
    ubuntu 15.10 64bit 下 steam无法启动
    ubuntu下使用OBS开斗鱼直播
    sql server 2008 management studio安装教程
    navicat for mysql 破解版
    nginx 重写去掉index.php
    phpstorm 注册码破解
    tp where使用数组条件,如何设置or,and
    PHPstorm 配置主题
    IE下无法保存Cookie和Session问题
    GitLab的安装及使用
  • 原文地址:https://www.cnblogs.com/lyt020321/p/11636034.html
Copyright © 2011-2022 走看看