USACO Section 1.3:

Source: Internet
Author: User

From yesterday to today, I made four simple questions. A new page is enabled.

Milk: It's easy and greedy. Select a cheaper price first.

Code:


[Cpp]
/*
ID: duanjia2
PROG: milk
LANG: C ++
*/
 
# Include <iostream>
# Include <algorithm>
# Include <fstream>
Using namespace std;
Struct node
{
Int p,;
} S [5005];
Bool cmp (node x, node y)
{
Return x. p <y. p;
}
Int main ()
{
Ifstream fin ("milk. in ");
Ofstream fout ("milk. out ");
Int n, m, sum, I;
Fin> n> m;
For (I = 0; I <m; I ++) fin> s [I]. p> s [I].;
Sort (s, s + m, cmp );
Sum = 0;
For (I = 0; I <m; I ++ ){
If (n> = s [I].)
N-= s [I]. a, sum + = s [I]. p * s [I].;
Else {
Sum + = n * s [I]. p;
Break;
}
}
Fout <sum <endl;
// System ("pause ");
Return 0;
}

Barn1: tell stories about Guan Niu. That is to say, there are 50 bullpens, some of which have cows, some of which do not, and the door of the bullpen is broken. Now you have m boards, and you want to cover all the bullpens with cows. The Boards can be any longer, each bullpen is equivalent to a unit of wood. Ask how many boards you need at least. Let's assume that 50 of them are covered, and then we can cut the biggest gap between the 1-1.
Code:


[Cpp]
/*
ID: duanjia2
PROG: barn1
LANG: C ++
*/
# Include <iostream>
# Include <algorithm>
# Include <fstream>
Using namespace std;
Bool cmp (int a, int B)
{
Return a> B;
}
Int main ()
{
Ifstream fin ("barn1.in ");
Ofstream fout ("barn1.out ");
Int m, s, c, I, j, ans;
Int B [1, 205], d [2, 200];
Fin> m> s> c;
For (I = 0; I <c; I ++)
Fin> B [I];

If (m> = c)
Fout <c <endl;
Else {
Sort (B, B + c );
For (I = 1, j = 0; I <c; I ++)
If (B [I]-B [I-1]> 1)
D [j ++] = B [I]-B [I-1]-1;
Sort (d, d + j, cmp );
Ans = B [0]-1 + 50-b [C-1];

For (I = 0; I <m-1; I ++)
Ans + = d [I];

Fout <50-ans <endl;
}
// System ("pause ");
Return 0;
}

Calfflac: Maximum number of replies. I suggest you check the manacher algorithm on the Internet. I have done this before, so this is also the case.
Code:


[Cpp]
/*
ID: duanjia2
PROG: calfflac
LANG: C ++
*/
# Include <iostream>
# Include <stdio. h>
# Include <string. h>
# Include <fstream>
Using namespace std;
Int main ()
{
Ifstream fin ("calfflac. in ");
Ofstream fout ("calfflac. out ");
Int I, id, mx, len, pt [20005], j, r [20005];
Char str [200005], s [20005], m [50005], ch;

Memset (pt, 0, sizeof (pt ));
For (I = 0, j = 0; str [I] = fin. get (), str [I]> 0; I ++ ){
If (str [I]> = 'A' & str [I] <= 'Z ')
S [j] = str [I], pt [j ++] = I;
If (str [I]> = 'A' & str [I] <= 'Z ')
S [j] = str [I]-('A'-'A'), pt [j ++] = I;
}
S [j] = '\ 0'; len = j;
// Cout <len <endl;
M [0] = '@';
For (j = 1, I = 0; I <len; I ++ ){
M [j ++] = '#';
M [j ++] = s [I];
}
M [j ++] = '#', m [j] = '\ 0 ';
Len = j;

// Manacher algorithm.
Memset (r, 0, sizeof (r ));
Mx = 0, id = 0;
For (I = 1; I <len; I ++ ){

If (I <mx) r [I] = min (r [2 * id-I], mx-I );
Else r [I] = 1;

While (m [I + r [I] = m [I-r [I]) r [I] ++;

If (r [I] + I> mx ){
Mx = r [I] + I;
Id = I;
}
}
Mx = 0;
For (I = 1; I <len; I ++)
If (mx <r [I])
Mx = r [I], id = I;
Len = pt [(id + r [id]-3)/2];
Fout <mx-1 <endl;
For (j = pt [(id-r [id])/2]; j <= len; j ++)
Fout <str [j];
Fout <endl;

// System ("pause ");
Return 0;
}

Crypt1: I can't tell you how greedy it is. You have to see what others have done.
Code:


[Cpp]
/*
ID: duanjia2
PROG: crypt1
LANG: C ++
*/
 
# Include <iostream>
# Include <algorithm>
# Include <string. h>
# Include <fstream>
Using namespace std;
Int f [10];
Bool Judge (int n)
{
While (n ){
If (! F [n % 10]) return false;
N/= 10;
}
Return true;
}
Int main ()
{
Ifstream fin ("crypt1.in ");
Ofstream fout ("crypt1.out ");
Int I, j, n, cnt;
Fin> n;
Memset (f, 0, sizeof (f ));
For (I = 0; I <n; I ++ ){
Fin> j;
F [j] = 1;
}
Cnt = 0;
For (I = 111; I <= 999; I ++ ){
If (Judge (I )){
For (j = 11; j <= 99; j ++)
If (Judge (j) & I * j <10000 & (j % 10) * I <1000 & (j/10) * I <1000 & Judge (I * (j % 10) & Judge (I * (j/10) & Judge (I * j ))
Cnt ++;
}
} Www.2cto.com
Fout <cnt <endl;
// System ("pause ");
Return 0;
}

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.