最近在倒腾准备考试,做题有点少啊。。。得多刷点了啊。。sad。。
A。水题看懂题意就可以了啊,一开始竟然忘记了人有两只手,哈哈,真逗啊、、、
Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4 × 4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most k panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.
You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing.
The first line contains a single integer k (1 ≤ k ≤ 5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit i was written on the panel, it means the boy has to press that panel in time i. If period was written on the panel, he doesn't have to press that panel.
Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes).
1 .135 1247 3468 5789
YES
5 ..1. 1111 ..1. ..1.
YES
1 .... 12.1 .2.. .2..
NO
In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands.
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define M 10010
#define LL long long
#define INF 1 << 30;
using namespace std;
int main()
{
char s;
int n, sum[20];
int i, j;
while(cin >>n)
{
memset(sum , 0 , sizeof(sum));
for(i = 0; i < 4; i++)
for(j = 0; j < 4; j++)
{
cin >>s;
if(s != '.')
{
sum[s-'0'] ++;
}
}
int flat = 0;
for(i = 1; i <= 9; i++)
if(sum[i] > 2*n)
flat = 1;
if(!flat)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
B。注意数据范围啊。。。
We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3,S(114514) = 6.
You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(n)·k to add the number n to the sequence.
You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length.
The first line contains three integers w (1 ≤ w ≤ 1016), m (1 ≤ m ≤ 1016), k (1 ≤ k ≤ 109).
Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64dspecifier.
The first line should contain a single integer — the answer to the problem.
9 1 1
9
77 7 7
7
114 5 14
6
1 1 2
0
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define M 1001000
#define LL __int64
#define INF 1 << 30
using namespace std;
int num(LL n)
{
int t = 0;
while(n)
{
t++;
n /= 10;
}
return t;
}
int main()
{
unsigned LL w, m, k;
unsigned LL sum, cnt;
while(cin >>w>>m>>k)
{
sum = 0;
cnt = 0;
while(1)
{
int s = num(m);
//cout <<s<<endl;
LL t = (LL)pow(10.0, s);
LL f = t-m;
if(w >= f*s*k)
{
w -= f*s*k;
cnt += f;
}
else
{
LL p = w/(s*k);
w = 0;
cnt += p;
}
if(w <= 0)
break;
else
m = t;
}
cout <<cnt<<endl;
}
return 0;
}
C。这个题有点sad啊、、一开始想错了啊,二分找的结果会有少的情况啊。。。其实最少也就n/2种情况啊,O(n)一遍查找就可以了啊..
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos.
The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.
The first line contains a single integer — n (1 ≤ n ≤ 5·105). Each of the next n lines contains an integer si — the size of the i-th kangaroo (1 ≤ si ≤ 105).
Output a single integer — the optimal number of visible kangaroos.
8 2 5 7 6 9 8 4 2
5
8 9 1 6 2 6 5 8 3
5
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define M 1001000
#define LL long long
#define INF 1 << 30;
using namespace std;
int main()
{
int n;
int f[M];
int i;
while(cin >>n)
{
for(i = 0; i < n; i++)
cin >>f[i];
sort(f, f+n);
int p = n-1;
int sum = 0;
for(i = n/2-1; i >= 0; i--)
{
if(f[p] >= 2*f[i])
{
p--;
sum ++;
}
}
cout <<n-sum<<endl;
}
return 0;
}