分析:并不是特别难的一道题,用到了贪心算法.

首先可以明确的一点是我们要尽量偷贡献最大的数据,要先满足每一个公司的贡献都大于等于K,以这个作为首要条件.那么我们可以先把每个快递公司的快递按照贡献从大到小排序,每次选贡献最大的,满足要求了就考虑下一个快递公司,如果过程中用超过了s个或者处理完后发现还有快递公司没有满足要求就输出无解.

上面只是满足了第一个要求,这时可能s个还没有用满,那么我们在按照贡献全体排一次序,看哪些没有用加上去就好了.

中途犯了一个很愚蠢的错误:直接把vis数组赋值为i,其实这是不对的,每一个vis应该对应快递的ID,而不是排序后的i!

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n, m, s, k;
long long ans,tot, cnt, sum, cnt2;
bool flag = false,can[]; struct node
{
long long e, t;
bool vis;
}a[]; bool cmp1(node a, node b)
{
if (a.e == b.e)
return a.t < b.t; //实际上是看谁的贡献最大
return a.e < b.e;
} bool cmp2(node a, node b)
{
return a.t < b.t;
} int main()
{
scanf("%d%d%d%d", &n, &m, &s, &k);
for (int i = ; i <= m; i++)
{
long long e, t;
scanf("%lld%lld", &e, &t);
if ( - t < )
{
a[++tot].e = e;
a[tot].t = - t;
}
}
sort(a + , a + + tot, cmp1);
if (a[tot].e < n)
{
printf("-23333333\n");
return ;
}
for (int i = ; i <= tot; i++)
{
if (can[a[i].e])
continue;
sum -= a[i].t;
cnt++;
a[i].vis = ;
if (cnt > s)
{
flag = ;
break;
}
if (sum >= k)
{
ans += sum;
sum = ;
can[a[i].e] = ;
}
}
for (int i = ; i <= n; i++)
if (!can[i])
{
flag = ;
break;
}
if (flag)
printf("-23333333\n");
else
{
sort(a + , a + tot + , cmp2);
for (int i = ; i <= tot; i++)
{
if (!a[i].vis)
{
cnt++;
ans -= a[i].t;
if (cnt == s)
break;
}
}
printf("%lld\n", ans);
} return ;
}

noip模拟赛 天天寄快递的更多相关文章

  1. noip模拟赛 天天和不可描述

    分析:直接就这么翻肯定是不行的,换一种想法:有括号就是把括号里的字符串倒着输出,如果在括号里又遇到了括号就继续倒着输出,相当于递归. 我们可以用递归直接做,也可以用一层循环搞定,每次从左括号跳到右括号 ...

  2. NOIP模拟赛16

    NOIP2017金秋冲刺训练营杯联赛模拟大奖赛第一轮Day2 期望得分:100+100+ =200+ 实际得分:100+40+70=210 T1天天寄快递 直接模拟,代码丢了...... T2天天和不 ...

  3. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  4. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  5. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  6. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

  7. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

  8. 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...

  9. 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...

随机推荐

  1. 基于Numpy的神经网络+手写数字识别

    基于Numpy的神经网络+手写数字识别 本文代码来自Tariq Rashid所著<Python神经网络编程> 代码分为三个部分,框架如下所示: # neural network class ...

  2. H - Where is the Marble?(set+vector)

    Description Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers wr ...

  3. 因Window服务器自动更新并重启导致WebSphere服务停止服务故障一例

    最近公司购买了两台Windows Server 2008 R2服务器用于提供提供Web服务,A机器安装了IHS+DM+WAS8.5集群,B机器安装了Oracle11gR2用于数据存储,两台机器均可连接 ...

  4. Android 性能优化(12)网络优化( 8)Monitoring the Battery Level and Charging State

    Monitoring the Battery Level and Charging State PreviousNext This lesson teaches you to Determine th ...

  5. 【[转】MySql模糊查询

    转自:http://chenpeng.info/html/2020 MySQL提供标准的SQL模式匹配,以及一种基于象Unix实用程序如vi.grep和sed的扩展正则表达式模式匹配的格式. 一.SQ ...

  6. Python中*args和**kwargs的使用

    函数定义 使用*args和**kwargs传递可变长参数: *args用作传递非命名键值可变长参数列表(比如元组) **kwargs用作传递键值可变长参数列表(比如字典) 函数入参 *args 传递一 ...

  7. Sonar 规则

    bug类型: 1.".equals()" should not be used to test the values of "Atomic" classes. ...

  8. Angular——内置服务

    $location <!DOCTYPE html> <html lang="en" ng-app="App"> <head> ...

  9. WinRT ListView间隔变色(一)

    我们知道,在WPF里,MSDN提供了三种方法 1.使用转换器Converter 2.继承ListView类,自己处理 3.使用StyleSelctor 到了WinRT的世界了 1. Winrt中Set ...

  10. treetable adding nodes at root level

    describe("loadBranch()", function() {     beforeEach(function() {     this.newRows = " ...