A - Air Conditioned Minions +H - Association for the Country of Mububa

A - Air Conditioned Minions
You are the boss of ACM (Air Conditioned Minions), an upstanding company with a single goal of world domination.
The company has NN minions. Each minion works evilly from early morning until evening inside a super secret bunker in Helsinki. After much deliberation, you decided to move your headquarters to Singapore. However, unlike Helsinki, Singapore is very hot, so the entire complex must be air conditioned. With strenuous working hours (under minimum wage too), it is imperative that all your minions work under optimal work condition. In particular, all minions must like the temperatures of the rooms they are in.
You are planning to construct several rooms in your new hideout, and assign your minions there. You fix the temperature of each room to any value you want (different rooms may have different temperatures). After you fix the temperatures, you will assign each of your minions to these rooms (a room can hold any number of minions). You want all minions to like the temperatures of their assigned rooms. Each minion likes an interval of temperature, and these preferences will be given to you.
Air conditioners are very expensive to maintain. Thus, you want to construct as few rooms as possible. What is the minimum number of rooms you need to set up such that it would be possible to assign minions to rooms as discussed earlier?
Input
The first line contains a non-negative integer 2≤N≤1002≤N≤100, giving the number of minions in your company. The next NN lines each describe the temperature preferences of all your minions. The ii-th line consists of two single space separated integers LL and UU (1≤L≤U≤2N1≤L≤U≤2N), which denotes that the ii-th minion likes any temperature between LL and UU, inclusively.
Output
Print an integer denoting the minimum number of rooms you need to construct.
Sample Data Explanation
In the first example, one of the possible solutions is to setup two rooms — one with temperature 22, and another with temperature 55. The first two minions can be assigned to the first room, while the third minion can be assigned to the second room.

Sample Input 1
Sample Output 1

3
1 2
2 4
5 6

2

Sample Input 2
Sample Output 2
5
1 2
3 5
4 6
7 9
8 10
3

题意为如果一个房间只有一个温度,给出不同的房间温度范围,问有几个温度可以满足需求,
如1-3,2-4,5-6;只要两个就够了;
而特殊的如1-4,2-2,2-5,3-3;则需要2个就够了;

#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<cstdlib>
#include<iostream>
using namespace std;
int a[1000],b[1000],x,y,z,i,j,m,n,sum;
int main()
{
    scanf("%d",&x);
    for(z=1; z<=x; z++)
    {
        cin>>a[z]>>b[z];
    }
    for(i=1; i<=x; i++)
        for(j=i+1; j<=x; j++)
            if(a[i]>a[j])
            {
                swap(a[i],a[j]);
                swap(b[i],b[j]);
            }
            else if(a[i]==a[j]&&b[i]>b[j])
                {
                swap(a[i],a[j]);
                swap(b[i],b[j]);
            }
            //先排序,后从第一个开始向后如果有交集,继续往后,如果没有交集,则就是单独的一个温度;
            m=b[1];
            sum=1;
            for(i=1;i<x;i++)
            {
               if(m<a[i+1]){m=b[i+1];sum++;}//表示没有交集
               else m=min(m,b[i+1]);表示如果有交集 像1-32-4;则m必须满足两个区间,即为min(34);
            }
            cout<<sum<<endl;
    return 0;
}

H - Association for the Country of Mububa

                    You are the boss of ACM (Association for the Country of Mububa), an upstanding company with a single goal of world domination.Today, you have conquered the unnamed country of Mububa (how an unnamed country has a name is, of course, outside the scope of this problem). Mububa is known for its great, great, bananas. In light of this monumental achievement, you have decided to reward your executives with Mububa’s greatest treasure (which is obviously, bananas). You have prepared NN

briefcases, each contains a number of bananas. These briefcases are numbered from 11

through NN

.You reward your executives one by one in order from the least evil executive, to the most evil executive (still not comparably evil to you, of course). No two executives are equally evil. For each executive, you first decide how many briefcases you want to give him. If you decide to give an executive aa

briefcases, you give him the aa

briefcases with lowest numbers that you still have. Each executive you reward must receive at least one briefcase.It is important to be fair when distributing rewards. You do not want your executives to stage a hunger strike, after all. Thus, the rewards the executives received must reflect how evil they are. More rigorously, if executive AA

is more evil than executive BB

, then the total number of bananas received by executive AA

must be at least as large as the total number of bananas received by executive BB

.You know the number of bananas inside all of the briefcases. You want to reward as many executives as possible, but wants the distribution to still be fair (i.e. following the previous requirement) amongst them. What is the maximum number of executives you can reward this way?InputThe first line contains a non-negative integer 2≤N≤30002≤N≤3000

, giving the number of briefcases you have. Then follows a line with NN

integers, the ii

-th of which denotes the number of bananas in briefcase number ii

. Each briefcase contains between 11

and 109109

bananas, inclusively.OutputPrint the maximum number of executives you can reward with bananas.Sample Data explanationIn the first example, give briefcase 11

to the least evil executive, briefcase 22

to the second least evil executive, and briefcases 33

and 44

to the most evil executive.In the second example, give briefcase 11

to the least evil executive, briefcases 22

and 33

to the second least evil executive, and briefcases 44

, 55

, and 66

to the most evil executive.Sample Input 1Sample Output 14
1 2 1 2
3

Sample Input 2Sample Output 26
6 4 2 2 2 2
3
题意为给出数字序列,让你划定区间,使区间内数字总和从前往后是不减少的,即后面的大于等于前面的;
这时一般的算法已经不行了,如

#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<cstdlib>
#include<iostream>
using namespace std;
int x,y,z,i,j,sum;
long long int a[5000],m,n;
int main()
{
    scanf("%d",&x);
    for(z=1; z<=x; z++)
        scanf("%lld",&a[z]);
    m=a[1];
    n=0;
    sum=1;
    for(z=2; z<=x; z++)
    {
        n+=a[z];
        if(m<=n)
        {
            sum++;
            m=n;
            n=0;
        }
    }
    cout<<sum<<endl;
    return 0;
}

这是我第一时间想到的算法,但是如果是数据
5
3 3 1 4 4
代码输出的就是3;
但应该是4;
应该是 3 3+1 4 4;
而不是 3 3 1+4 ;
这时我看到了别人的算法,我才知道自己还差得远着呢;

#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<cstdlib>
#include<iostream>
using namespace std;
long long int x,y,z,m,n,a[5000],b[5000],c[5000],i,j;
//a数组表示的是前几项的和;
//b数组表示的是前几项的最佳配置;
//c数组表示的是前几项的最佳人选;
int main()
{
    cin>>x;
    for(z=1; z<=x; z++)
    {
        cin>>a[z];
        a[z]+=a[z-1];
    }
    for(i=1; i<=x; i++)
        for(j=i-1; j>=0; j--)
        {
            if(a[i]-a[j]>=b[j])//如果前几项的和比当时在b上的解要大,这说明前面的不是最优解;
            {
                b[i]=a[i]-a[j];
                c[i]=c[j]+1;
                break;
            }
        }
    cout<<c[x]<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值