Hdu 4864 Task greedy and hdu4864task greedy

Source: Internet
Author: User

Hdu 4864 Task greedy and hdu4864task greedy

Question: There are n machines and m tasks. Each machine can complete one task at most. For each machine, there is a maximum run time xi and level yi. For each task, there is also a run time xj and level yj. Only when xi> = xj and yi> = yj, machine I can complete task j and get 500 * xj + 2 * yj money. Ask how many tasks can be completed, and when there are multiple situations, output the most money.

Question:

Sort the task x in ascending order (y in descending order ). Then the machine is sorted by the same sorting method. Start traversing the task, find all xi (xi> = xj), and select the smallest running machine with yi as the task. Why is it so greedy? If there is still a task (xk, yk) that this machine can be used, but xj> = xk, so more money is obtained. j is preferred; if k cannot use this machine, no other machine can be used. Unless it is a new machine, but the newly added machine cannot complete task j, therefore, the maximum number of tasks is guaranteed.



Code:

#include <iostream>#include <cstdio>#include <cstring>#include <ctime>#include <algorithm>#include <cmath>#include <queue>#include <vector>using namespace std;#define LL __int64const int maxn=1e5+10;struct node{    int x,y;}e[maxn],f[maxn];int c[101];int cmp(node a,node b){    if(a.x==b.x)return a.y>b.y;    return a.x>b.x;}int main(){    //freopen("C:\\Documents and Settings\\Administrator\\×ÀÃæ\\in.txt","r",stdin);    //freopen("C:\\Documents and Settings\\Administrator\\×ÀÃæ\\out.txt","w",stdout);    //double a = clock();    int n,m;    while(scanf("%d%d",&n,&m)!=EOF)    {        int i,j,k,num=0;        LL ans=0;        for(i=0;i<n;i++)            scanf("%d%d",&e[i].x,&e[i].y);        for(i=0;i<m;i++)            scanf("%d%d",&f[i].x,&f[i].y);        sort(e,e+n,cmp);        sort(f,f+m,cmp);        memset(c,0,sizeof(c));        for(i=0,j=0;i<m;i++)        {            while(j<n&&e[j].x>=f[i].x)            {                c[e[j].y]++;                j++;            }            for(k=f[i].y;k<=100;k++)            {                if(c[k])                {                    num++;                    c[k]--;                    ans=ans+500*f[i].x+2*f[i].y;                    break;                }            }        }        printf("%d %I64d\n",num,ans);    }    //double b = clock();    //printf("%lf\n", (b - a) / CLOCKS_PER_SEC);    return 0;}



HDU 1042 expert

For your reference, it must be correct.
# Include <iostream>
Using namespace std;

Int main (void)
{
Int carry, digit, temp, I, j, n;

While (cin> n)
{
Int a [200000] = };
Digit = 1;
Carry = 0;
For (I = 2; I <= n; I ++)
{
For (j = 1, carry = 0; j <= digit; j ++)
{
Temp = a [j] * I + carry;
A [j] = temp % 10;
Carry = temp/10;
}
While (carry)
{
A [++ digit] = carry % 10;
Carry/= 10;
}

}

For (I = digit; I> 0; I --)
{
Cout <a [I];
}
Cout <endl;
}
Return 0;
}

Change of hdu1166 baseline pascal Line Segment tree

Line Segment tree
, Line segment tree Definition
Informatics competitions often encounter problems related to interval operations. When calculating the extreme values and sum of several segments, special data structures of line segments are used.
Line Segment tree binary tree T (AB ). parameter a and parameter B indicate the length of the interval [a, B] and its B-a are called the Interval Length. The line segment tree T (a, B) is also recursively defined:
If L> 1: [a, (a + B) div 2] T left son;
[(A + B) div 2, B] T right son
If L = l: T leaf node
Process object line segments or ranges. Set the range to [1 .. n] divide some [I, I + 1] Each unit area corresponds to a line segment tree leaf node. Each node uses variables to record the number of line segments that overwrite the node. Use a line segment tree to know that the endpoint of the specified interval can take values, set A [1 .. n] For any undefined closed range in the same endpoint set in a small large permutation area P = [xy]. save l ≤ I ≤ j ≤ n so that x = a [I] and y = a [j], Li I, j is called x, y number note: even if the real coordinate line segment tree has only integer meanings, the ranges [x, y] x and y are all integers. that is, the coordinate number of the vertex in the original interval.
Generally, the line segment Tree node type is defined as follows:
Type linetree = ^ node
Node = record
I, j: integer; {node indicates the vertex ID of the partition question I. j}
Count: integer; {Number of overwriting node zones}
Lchild, rchild: linetree; {two subnodes of a binary tree}
End;
Figure 6-22 typical line segment tree description interval endpoint has 10 values

Ii. Basic operations and Applications of line tree
The line segment tree has some important features. line Segment tree Balance Tree. the depth exceeds log2L. The second line segment tree divides any line segment in the area question into lines that exceed 2log2L. The line segment tree energy O (log2L) the following describes how to perform operations on a line segment tree when inserting, deleting, or searching a line segment within the specified time.
[Example 6-14] Ticket Sales System
[Problem description]
A certain train passes through city c. there are a total of s seats on the 1c train on the city no. the Railway Bureau stipulates that tickets sold can only be seated. that is, all passengers on the bus have a ticket sales system run by a computer. each ticket request contains three parameters. O and DN are used to represent the origin site D. N ticket count ticketing system accepts or accepts the ticket application. the ticket application is accepted only when there are N points N seats on the train in the OD section. Please write a program to implement automatic ticketing.
Input:
Input File: RAILWAY. IN, the first line contains three spaces to separate integers c, s, and R. its l ≤ c ≤ 600001 ≤ s ≤ 600001 ≤ R ≤ 60000c city number of s trains on the seat number R all ticket tickets application total number next R lines each ticket application. use three spaces to separate the integer OD and N to represent the start station of O. d. Visual site. N number of ticket stations, its l ≤ D ≤ cl ≤ O ≤ c. all ticket sales applications are provided from morning and evening based on the application time
Output:
Output file: RAlLWAY. OUT. There are a total of R rows. Each row outputs YES or NO, indicating that the current ticket sales application is accepted or accepted.
[Example input] RAIlWAY. IN
4 6 4
L 4 2
I 3 2
2 4 3
1 2 3
[Example output] RAILWAY. OUT
YES
YES
NO
NO
[Problem Analysis]
In this case, when the number of online statistics and search questions-interval insertion and search questions is relatively small, it is easy to simply simulate the scale of this question by 60,000. simple quasi-complexity O (n2) 60,000x60,000 = 3,600,000,000 The amount of computation cannot bear. Therefore, we must use special data structures and algorithms to reduce the time complexity.
Interval insertion and searching make it easy for us to think of line segments (intervals) of data structures. The time complexity of inserting and searching a line segment tree is O (log2n) only this topic is special. To search for segments, you must design a line segment tree with the function of searching for segments.
Let's design a line segment tree.
First. as a line segment tree. the number of times each record interval on the tree is overwritten is required. in this question, we need to record the two values of the period in each interval. except for the two values. we can also see that we need to record other information. We may as well, the shader line segment tree only records two values.
Maintenance Operation key record value for line segment tree maintenance refers to the insertion and search process. Maintenance complexity within the log2n level ...... the remaining full text>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.