Codeforces Round #645 (Div. 2)

22 篇文章 0 订阅

A. Park Lighting

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.

The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.

You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).
在这里插入图片描述
The park sizes are: n=4, m=5. The lighted squares are marked yellow. Please note that all streets have length 1. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit.
Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.

Input
The first line contains a single integer t (1≤t≤104) — the number of test cases in the input. Then t test cases follow.

Each test case is a line containing two integers n, m (1≤n,m≤104) — park sizes.

Output
Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.

Example
inputCopy
5
1 1
1 3
2 2
3 3
5 3
outputCopy
1
2
2
5
8
Note
Possible optimal arrangement of the lanterns for the 2-nd test case of input data example:
在这里插入图片描述
Possible optimal arrangement of the lanterns for the 3-rd test case of input data example:
在这里插入图片描述

大概就是 贪心 ,读一遍题 1A

#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int main(int argc,char* argv[]) {
	int n,m,T; scanf("%d",&T);
	while(T--) {
		scanf("%d %d",&n,&m);
		printf("%d",n * m / 2 + (n * m % 2));
		if(T) printf("\n");
	}
	
	return 0;
}

B. Maria Breaks the Self-isolation

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Maria is the most active old lady in her house. She was tired of sitting at home. She decided to organize a ceremony against the coronavirus.

She has n friends who are also grannies (Maria is not included in this number). The i-th granny is ready to attend the ceremony, provided that at the time of her appearance in the courtyard there will be at least ai other grannies there. Note that grannies can come into the courtyard at the same time. Formally, the granny i agrees to come if the number of other grannies who came earlier or at the same time with her is greater than or equal to ai.

Grannies gather in the courtyard like that.

Initially, only Maria is in the courtyard (that is, the initial number of grannies in the courtyard is 1). All the remaining n grannies are still sitting at home.
On each step Maria selects a subset of grannies, none of whom have yet to enter the courtyard. She promises each of them that at the time of her appearance there will be at least ai other grannies (including Maria) in the courtyard. Maria can call several grannies at once. In this case, the selected grannies will go out into the courtyard at the same moment of time.
She cannot deceive grannies, that is, the situation when the i-th granny in the moment of appearing in the courtyard, finds that now there are strictly less than ai other grannies (except herself, but including Maria), is prohibited. Please note that if several grannies appeared in the yard at the same time, then each of them sees others at the time of appearance.
Your task is to find what maximum number of grannies (including herself) Maria can collect in the courtyard for the ceremony. After all, the more people in one place during quarantine, the more effective the ceremony!

Consider an example: if n=6 and a=[1,5,4,5,1,9], then:

at the first step Maria can call grannies with numbers 1 and 5, each of them will see two grannies at the moment of going out into the yard (note that a1=1≤2 and a5=1≤2);
at the second step, Maria can call grannies with numbers 2, 3 and 4, each of them will see five grannies at the moment of going out into the yard (note that a2=5≤5, a3=4≤5 and a4=5≤5);
the 6-th granny cannot be called into the yard — therefore, the answer is 6 (Maria herself and another 5 grannies).
Input
The first line contains a single integer t (1≤t≤104) — the number of test cases in the input. Then test cases follow.
The first line of a test case contains a single integer n (1≤n≤105) — the number of grannies (Maria is not included in this number).
The second line contains n integers a1,a2,…,an (1≤ai≤2⋅105).

It is guaranteed that the sum of the values n over all test cases of the input does not exceed 105.
Output
For each test case, print a single integer k (1≤k≤n+1) — the maximum possible number of grannies in the courtyard.
Example
inputCopy
4
5
1 1 2 2 1
6
2 3 4 5 6 7
6
1 5 4 5 1 9
5
1 2 3 5 6
outputCopy
6
1
6
4
Note
In the first test case in the example, on the first step Maria can call all the grannies. Then each of them will see five grannies when they come out. Therefore, Maria and five other grannies will be in the yard.

In the second test case in the example, no one can be in the yard, so Maria will remain there alone.

The third test case in the example is described in the details above.

In the fourth test case in the example, on the first step Maria can call grannies with numbers 1, 2 and 3. If on the second step Maria calls 4 or 5 (one of them), then when a granny appears in the yard, she will see only four grannies (but it is forbidden). It means that Maria can’t call the 4-th granny or the 5-th granny separately (one of them). If she calls both: 4 and 5, then when they appear, they will see 4+1=5 grannies. Despite the fact that it is enough for the 4-th granny, the 5-th granny is not satisfied. So, Maria cannot call both the 4-th granny and the 5-th granny at the same time. That is, Maria and three grannies from the first step will be in the yard in total.

【题目大意】
每个奶奶有一个ai值,只有当当前院子里奶奶的人数大于等于ai(除去自己),第i位奶奶才可以进入院子,问最多能有多少奶奶来到院子里
【题目分析】
本想的是一波一波人次模拟,结果最后发现,所有奶奶一波到来就好,然后题解就是:排序 + 倒序找一个最大的合适的值

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define Maxn 100005
// 在胡 qiu 股当中发现的做法 
using namespace std;
int a[Maxn];
int main(int argc,char* argv[])  {
	int T,n;  scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		for(int i=1; i<=n; i++) scanf("%d",&a[i]);
		sort(a + 1,a + 1 + n);
		int p = n,Ans = 1;
		while(p >= 0 && a[p] > p) p--;
		printf("%d",p + 1);
		if(T) printf("\n");
	}
	
	return 0;
}

C. Celex Update

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
During the quarantine, Sicromoft has more free time to create the new functions in “Celex-2021”. The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down from the upper left corner as follows:
在这里插入图片描述
The cell with coordinates (x,y) is at the intersection of x-th row and y-th column. Upper left cell (1,1) contains an integer 1.
The developers of the SUM function don’t sleep either. Because of the boredom, they teamed up with the developers of the RAND function, so they added the ability to calculate the sum on an arbitrary path from one cell to another, moving down or right. Formally, from the cell (x,y) in one step you can move to the cell (x+1,y) or (x,y+1).

After another Dinwows update, Levian started to study “Celex-2021” (because he wants to be an accountant!). After filling in the table with the GAZ-GIZ function, he asked you to calculate the quantity of possible different amounts on the path from a given cell (x1,y1) to another given cell (x2,y2), if you can only move one cell down or right.

Formally, consider all the paths from the cell (x1,y1) to cell (x2,y2) such that each next cell in the path is located either to the down or to the right of the previous one. Calculate the number of different sums of elements for all such paths.

Input
The first line contains one integer t (1≤t≤57179) — the number of test cases.

Each of the following t lines contains four natural numbers x1, y1, x2, y2 (1≤x1≤x2≤109, 1≤y1≤y2≤109) — coordinates of the start and the end cells.

Output
For each test case, in a separate line, print the number of possible different sums on the way from the start cell to the end cell.

Example
inputCopy
4
1 1 2 2
1 2 2 4
179 1 179 100000
5 7 5 7
outputCopy
2
3
1
1
Note
In the first test case there are two possible sums: 1+2+5=8 and 1+3+5=9.
在这里插入图片描述
【题目大意】
如图的蛇形图,给出起点和终点坐标,问从起点到终点的路径和有多种可能
【题目分析】
在这里插入图片描述
在最小的3*3方阵中这样就可以出现两个sum相等的路径昨天晚上我在做的时候,真的是一点吧思路都没有,后来发现了这个情况,以为需要用的排列组合 以及 容斥原理什么的,今天早上起来看题解,,,,,
显然,从起点一直向右走,然后向下走,这样的sum是最小的;从起点一直向下走,然后一直向右走这样的sum是最大的;然后,通过观察,会发现,我们是有办法让走过的路径从min一直变化到max的,而且每次只需要递增1。
然后每行从最右边到最左边"拐弯",一共就能拐△x△y次,然后加上最小值的那一条路径,总共就是△x△y+1

#include<iostream>
#include<cstring>
#include<cstdio>
#define LL long long 
using namespace std;

int main(int argc,char* argv[]) {
	int T; LL x1,x2,y1,y2;
	scanf("%d",&T);
	while(T--) {
		scanf("%lld %lld %lld %lld",&x1,&y1,&x2,&y2);
		LL Ans = (x2 - x1) * (y2 - y1) + 1;
		printf("%lld\n",Ans);
	}
	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值