CF1371A - Magical Sticks
C o d e : \mathcal{Code:} Code:
//CF1371A
#include <cstdio>
using namespace std;
int t;
long long n;
int main(){
scanf("%d",&t);
while(t--){
scanf("%lld",&n);
printf("%lld\n",n % 2 ? ((n / 2) + 1) : (n / 2));
}
return 0;
}
CF1371B - Magical Calendar
题意简述
求大小为 n \bm n n,左右跨度不超过 r \bm r r 的连通块个数。
思路
找规律。
容易发现,方案数的排列是一个等差数列:
- 当 n ≤ r \bm{n\le r} n≤r 时, Ans = n ( n − 1 ) 2 + 1 \bm{\text{Ans}=\dfrac{n(n-1)}{2}}+1 Ans=2n(n−1)+1。
- 否则, Ans = r ( r + 1 ) 2 \bm{\text{Ans}=\dfrac{r(r+1)}{2}} Ans=2r(r+1)。
输出即可。
C o d e : \mathcal{Code:} Code:
//CF1371B
#include <iostream>
using namespace std;
int t;
long long n,r;
int main(){
ios::sync_with_stdio(0);
std::cin >> t;
while(t--){
std::cin >> n >> r;
unsigned long long k;
if(n <= r)
k = ((n - 1) * n / 2 + 1);
else
k = ((r + 1) * r / 2);
std::cout << k << std::endl;
}
return 0;
}
CF1371C - 题解
题意简述
略
思路
不考虑 First 类客人,因为他们的选择不影响 Second 类客人。
直接判断饼干能否满足 Second 类客人的需要。
即要使
a
+
b
≥
m
+
n
&
n
≤
min
(
a
,
b
)
a+b\ge m+n\And n\le\min(a,b)
a+b≥m+n&n≤min(a,b)。
C o d e : \mathcal{Code:} Code:
//CF1371C
#include <iostream>
using namespace std;
typedef unsigned long long ull;
int t;
ull a,b,m,n;
int main(){
ios::sync_with_stdio(0);
std::cin >> t;
while(t--){
std::cin >> a >> b >> m >> n;
ull tmp = (a < b) ? a : b;
printf("%s\n",(n <= tmp && (a + b) >= (m + n)) ? "Yes" : "No");
}
return 0;
}
End … … \text{End}\dots\dots End……