A. Setting up Camp
题意:给你a,b,c,a表示独居的人的个数,b表示可以同居的人的个数,但是必须要一屋子三个人,c表示可以两个人一起住也可以三个人一起住的人数,问最少需要几间屋子?
题解:先看a,a有多少人就需要多少间屋子,再看b,如果c的人数无法和b凑成3的倍数,那么一定是无解,其他的情况就是让c和b凑出最大的3的倍数,剩下的c最多组成一个屋子,得解。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {
ll x = 0, f = 1 ;
char c = getchar() ;
while (c > '9' || c < '0') {
if (c == '-')
f = -1 ;
c = getchar() ;
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0' ;
c = getchar() ;
}
return x * f ;
}
bool vis[maxn] ;
ll t , n , d , k , a[maxn] , b[maxn] , sum[maxn] , Sum[maxn] ;
void solve(){
n = read() ;
d = read() ;
k = read() ;
ll ans = n ;
ll res = (d + 3 - 1) / 3 ;
res = res * 3 ;
res = res - d ;
if(k >= res){
ll Ans = (k + d) / 3 ;
Ans = Ans * 3 - d ;
// cout << Ans << endl ;
cout << ans + ((k + d) / 3ll) + ((k - Ans) > 0 ? 1 : 0) << endl ;
return ;
}
else{
cout << -1 << endl ;
}
}
int main(){
t = read() ;
while(t --){
solve() ;
}
return 0 ;
}
B. Fireworks
题意:给你a , b , c ,一共有两种烟花,第一种每隔a分钟发射一次,第二种每隔b分钟发射一次,问找到一个区间满足
,问找到一个区间能同时看到最多的烟花数量是多少?
题解:很明显,从
开始,然后再看c分钟能放多少个烟花即可,答案就是
。
代码:
#include<bits/stdc++.h>
usin