F-
问题 F: Teacher’s Day
时间限制: 1 Sec 内存限制: 128 MB 提交: 64 解决: 11 [ ][ ][ ]题目描述
Teacher’s Day is coming, a group of n students decided to buy gifts. The store offered them M gifts. The price is different for different gifts, buying the j-th gift costs pj yuan. In total, the boys’ shared budget is a yuan.Besides, each of them has his own personal money, the i-th student has bi personal yuan.The shared budget can be spent on any student, but each boy’s personal money can be spent on buying only his gift. Each boy can rent at most one gift, one cannot give his gift to sombody else.What maximum number of students will able to buy gifts?What minimum sum of personal money will they have to spend in total to let as many students buy gifts as possible?
输入
The first line of the input contains three integers n, m and a (1 ≤ n, m ≤ 1e5; 0 ≤ a ≤ 1e9). The second line contains the sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 1e4), where bi is the amount of the i-th student's personal money. The third line contains the sequence of integers p1, p2, ..., pm (1 ≤ pj ≤ 1e9), where pj is the price for renting the j-th gift.
输出
Print two integers r and s, where r is the maximum number of students that can buy a gift and s is the minimum total personal money needed to buy r gifts. If the students cannot buy any gifts, then r = s = 0.
样例输入
2 2 10
5 5
7 6
样例输出
2 3
二分 + 贪心
为获取 最大的购买个数, 二分查找最大区间, 然后补差值
#include#include #include #include #include #include #include #include #include #include #include
4198: Birthday present
时间限制: 1 Sec 内存限制: 128 MB 提交: 67 解决: 23 [ ][ ][ ]题目描述
Bob’s father’s birthday is coming,.Because Bob’s father is a math teacher so that Bob wanted to give him an array of positive intergers a of length n as a gift.His father thinks that an array’s beauty is the greatest common divisor of all its elements. Bob wants to give him as beautiful an array as possible. But the shop has only one array a left. So Bob wants to decrease some numbers in the array(no more than K for each number).Bob can obtain array b from array a if the following conditions hold: bi > 0; 0 ≤ ai - bi ≤ k for all 1 ≤ i ≤ n.Help Bob find the maximum possible beauty of the array he will give to his father .
输入
The first line contains two integers n and k (1 ≤ n ≤ 3·1e5; 1 ≤ k ≤ 1e6). The second line contains n integers ai (1 ≤ ai ≤ 1e6) — array a.
输出
In the single line print a single number — the maximum possible beauty of the resulting array.
样例输入
6 1
3 6 10 12 13 16
样例输出
3
D - 爆搜;
判断最大公因数,
只需要判断 a[i] %x < =k 的个数 =n 则 x 即为答案, x 从 最小的输入开始;
#include#include #include #include #include #include #include #include #include #include #include
问题 E: Make cubes
时间限制: 1 Sec 内存限制: 128 MB
提交: 76 解决: 20
[ ][ ][ ]
题目描述
When he was a little boy, Jieba had always been interested in geometry. One time, he got many pieces of colored square cards. For each color, he had as many pieces as he wanted. At that time, he decided to make some cubes using these cards. He wanted to know how many kinds of cubes could he make? (if one kind of cube can rotate to another kind, they will be seen the same)
输入
Every line of the input file defines a test case and contains one integer: the number of available colors n (0<n<1000)
输出
For each test case output on a single line the number of different kinds of cubes. Because the result may be too large, please mod the result with 1000000007.
样例输入
1
2
样例输出
1
10
这道题: 是 Burnside 染色 问题;
n 种 颜色 应为:
#include#include #include #include #include #include #include #include #include #include #include
I -
I: Coach's plan
时间限制: 2 Sec 内存限制: 128 MB 提交: 47 解决: 13 [ ][ ][ ]题目描述
NEUACM team holds summer training every year. This year n students participate in the training, and we provide m computers. Everyone has a suitability (0<=suitability<=1000) to every computer. Now our coach needs to draw up a plan, which satisfies: 1. every student uses one computer, and a computer can be used by no more than one student; 2. maximize the minimum suitability, which means if the answer is w, then everyone's suitability to his computer shouldn't be less than w. Hint: huge input, please use fast IO.
输入
The first line contains n and m (1<=n<=m<=500), indicating the number of students and computers. Next n lines describes every student's suitability to every computer, number in ith line and jth row means student[i]'s suitability to computer[j].
输出
A single number w in one line, which is described before.
样例输入
1 2
1 1
0
2 3
10 1 2
2 1 1
样例输出
10
2
找 最大的 里面最小的,
重判之前 - - 找列最小水过的, 隔壁找行最小水过, 然后双双 over, 隔隔壁 找行 最小列最小 取最小 水过的
竟然依然坚挺 - - mmp
水过代码:
找行列最小
#include#include #include using namespace std;int n,m,a[505][505],b[505],c[505];bool cmp(int x, int y){ return x > y;}int main(){ while(~scanf("%d%d",&n,&m)){ for(int i = 0; i < n; i ++){ for(int j = 0; j < m; j ++) scanf("%d",&a[i][j]); } for(int i = 0; i < n; i ++){ int mxx = a[i][0]; for(int j = 1; j < m; j ++) mxx = max(a[i][j],mxx); b[i] = mxx; } for(int j = 0; j < m; j ++){ int mxx = a[0][j]; for(int i = 1; i < n; i ++) mxx = max(a[i][j],mxx); c[j] = mxx; } sort(b,b+n,cmp); sort(c,c+m,cmp); printf("%d\n",min(c[n-1],b[n-1])); } return 0;}
正解 二分图匹配 +二分 :
把网格 从一维 转成 二维:
每行 选一个 每列 选一个, 并且 行列不能重复;
二分找到一个合适的, 然后将小于这个值得 划掉, 然后 取匹配剩下的是否有解:
用链式前向星 存储
123