B
//简单的发现选的位置不同,会有不同的收益
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n,k;
cin>>n>>k;
if(k<=(2*n-2)*2) cout<<(k+1)/2<<"\n";
else cout<<(n*2-2)+(k-(2*n-2)*2)<<"\n";
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
B
//转化为找到区间内不重不漏差 a~b(1<=a,b<=n)个相同
//而且相同的没有贡献,所以要删重
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin>>n;
vector<int> vc(n);
for(int i=0;i<n;i++){
cin>>vc[i];
}
sort(vc.begin(),vc.end());
vc.erase(unique(vc.begin(),vc.end()),vc.end());
int mmax=0;
for(int i=0;i<n;i++){
int len=lower_bound(vc.begin(),vc.end(),vc[i]+n)-vc.begin()-i;
mmax=max(mmax,len);
}
cout<<mmax<<"\n";
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
C
//明显的循环结构,但是实现的时候要剪枝
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void get_even_divisors(ll n, ll min_val, set<ll>& divisors){
if(n <= 0){
return; // 如果 n <= 0,直接返回,不做任何操作
}
ll sqrt_n = sqrt(n);
for(ll i = 1; i <= sqrt_n; i++){
if(n % i == 0){
if(i % 2 == 0 && i >= min_val){
divisors.insert(i);
}
ll div = n / i;
if(div != i && div % 2 == 0 && div >= min_val){
divisors.insert(div);
}
}
}
}
void solve(){
ll n, k;
cin >> n >> k;
set<ll> divisors;
ll num1 = n - k;
if(num1 >= 1){
ll min_val1 = max(2 * k - 2, (ll)2);
get_even_divisors(num1, min_val1, divisors);
}
ll num2 = n + k - 2;
if(num2 >= 1){
ll min_val2 = max(2 * k - 2, (ll)2);
get_even_divisors(num2, min_val2, divisors);
}
cout << divisors.size() << "\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}
C
// Problem: C. Sasha and the Casino
// Contest: Codeforces - Codeforces Round 926 (Div. 2)
// URL: https://codeforces.com/contest/1929/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//这道题翻译有点傻逼,一直看不懂,其实是道博弈题,就是问你时间无限,能不能赢无限
//钱.抓住倍率k和保底连输机制x,贪心的一直下1,然后看第x次必赢回本?
//不行,庄家直接断你皮城连败
//所以每次都要当作最后一次!!!,注意钱不够就输了哦
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
ll q,k,x;
cin>>k>>x>>q;
ll temp=0;//记录输的钱
for(ll i=1;i<=x;i++){
if(q<=0){//钱不够
cout<<"NO\n";
return ;
}
ll v=temp/(k-1)+1;//贪心的下,被断连败直接比输的钱多1,那就是赚
//不被断,就等着包金币
q-=v;//
temp+=v;//
}
if(q*(k-1)<=temp){//最后一次爆金币看看能不能回本
cout<<"NO\n";
}else{
cout<<"YES\n";
}
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}