A. Setting up Camp
时间限制:每个测试1秒
内存限制:每个测试256兆字节
输入:标准输入
输出:标准输出
组委会计划在游览结束后带领奥林匹克运动会的参赛选手进行徒步旅行。目前,正在计算需要搭帐篷的数量。已知每顶帐篷最多可容纳3人。
在参赛选手中,有a个内向型,b个外向型和c个综合型:
- 每个内向的人都想独自住在帐篷里。因此,内向者的帐篷里必须只有一个人–只有内向者自己。
- 每个外向者都希望与另外两个人住在一个帐篷里。因此,一个外向者的帐篷里必须正好有三个人。
- 每个综合型可以接受任何方式(独居、与一人同住或与两人同住)。
组委会非常尊重每位参赛者的意愿,因此他们希望满足所有参赛者的愿望。
告诉我们至少需要多少顶帐篷,以满足所有参赛者的愿望。如果无法满足,则输出-1。
输入
每个测试包含多个测试用例。第一行包含一个整数t(1≤t≤104)–测试用例的数量。接下来是测试用例的描述。
每个测试用例由一行描述,其中包含三个整数a、b、c(0≤a,b,c≤109)–分别是内向型、外向型和综合型的数量。
输出
对于每个测试用例,输出一个整数–最少需要的帐篷数,如果无法容纳参赛者,则输出-1。
示例1
输入
10
1 2 3
1 4 1
1 4 2
1 1 1
1 3 2
19 7 18
0 0 0
7 0 0
0 24 0
1000000000 1000000000 1000000000
输出
3
-1
3
-1
3
28
0
7
8
1666666667
说明
在第一个测试用例中,1顶帐篷将分配给内向者,1顶帐篷将由两名外向者和一名综合型共享,最后一顶帐篷将由两名综合型共享。总共需要3顶帐篷。
在第二个测试用例中,三个外向者将使用1个帐篷,1个帐篷将由一个内向者使用。然后,剩下一个外向者和一个综合型。这个外向者将无法与另外两个人一起生活。
解题思路
a一人一顶,b三人一顶,剩下的人和c进行组合,如果总人数小于3则无法组合。
题解
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <list>
#include <bitset>
#include <cmath>
#define endl '\n'
#define ft first
#define sd second
#define yes std::cout<<"Yes\n"
#define no std::cout<<"No\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<string, ll> psl;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pss> vpss;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef queue <int> qi;
typedef queue <ll> ql;
typedef queue <pii> qpii;
typedef queue <pll> qpll;
typedef queue <psi> qpsi;
typedef queue <psl> qpsl;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef priority_queue<string> pqs;
typedef priority_queue<pii> pqpii;
typedef priority_queue<psi> pqpsi;
typedef priority_queue<pll> pqpl;
typedef priority_queue<psi> pqpsl;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<char, int> mci;
typedef map<char, ll> mcl;
typedef map<string, int> msi;
typedef map<string, ll> msl;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> uml;
typedef unordered_map<char, int> umci;
typedef unordered_map<char, ll> umcl;
typedef unordered_map<string, int> umsi;
typedef unordered_map<string, ll> umsl;
void cinv(vi vec, int n)
{
for (int i = 1; i <= (n); i++)
cin >> (vec)[i];
}
void rcinv(vi vec, int n)
{
for (int i = (n); i >= 1; i--)
cin >> (vec)[i];
}
void coutv(vi vec, int n)
{
for (int i = 1; i <= (n); i++)
cout << (vec)[i] << " ";
cout << '\n';
}
void rcoutv(vi vec, int n)
{
for (int i = (n); i >= 1; i--)
cout << (vec)[i] << " ";
cout << '\n';
}
void solve()
{
int a, b, c;
cin >> a>>b>>c;
int cnt = a + (b + c + 2) / 3;
if (b % 3 != 0 && c + b % 3 < 3)
cnt = -1;
cout << cnt << endl;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
B. Fireworks
时间限制:每个测试111秒
内存限制:每个测试256256256兆字节
输入:标准输入
输出:标准输出
徒步旅行的其中一天恰逢节假日,因此决定晚上在营地安排一场节日焰火表演。为此,徒步旅行的组织者购买了两个烟花发射装置和大量的发射炮弹。
两个装置同时开启。第一个装置每隔aaa分钟(即发射后a,2⋅a,3⋅a,…a,2⋅a,3⋅a,\dotsa,2⋅a,3⋅a,…分钟)发射一次烟花。第二个装置每bbb分钟(即发射后b,2⋅b,3⋅b,…b,2⋅b,3⋅b,\dotsb,2⋅b,3⋅b,…分钟)发射一次烟花。
每个烟花在发射后的m+1m+1m+1分钟内都可以在天空中看到,也就是说,如果一个烟花是在装置开启后的xxx分钟后发射的,那么从xxx到x+mx+mx+m(包括首尾两分钟)的每一分钟都可以看到该烟花。如果一个烟花在另一个烟花mmm
分钟后发射,则两个烟花都将在一分钟内可见。
天空中最多可以同时看到多少枚烟花?
输入
每个测试包含多个测试用例。第一行包含一个整数ttt(1≤t≤1041≤t≤10^41≤t≤104)–测试用例的数量。接下来是测试用例的说明。
每个测试用例的第一行也是唯一一行包含整数aaa、bbb、mmm(1≤a,b,m≤10181≤a,b,m≤10^{18}1≤a,b,m≤1018)–第一次安装、第二次安装的发射频率,以及烟花在天空中可见的时间。
输出
对于每组输入数据,输出一个数字–可同时看到的最大烟花数量。
示例1
输入
6
6 7 4
3 4 10
7 8 56
5 6 78123459896
1 1 1
1 1 1000000000000000000
输出
2
7
17
28645268630
4
2000000000000000002
说明
在第一组输入数据中,烟花在天空中的可见时间为555分钟。由于第一个装置每666分钟发射一次烟花,第二个装置每777分钟发射一次烟花,因此同一装置发射的两个烟花不会同时出现在天空中。同时,在节日开始777分钟后,从第一个营地和第二个营地各发射一个烟花。因此,可以同时看到的烟花不会超过222个。
在第三组输入数据中,112112112分钟后可以看到171717个烟花:
烟花从第一个装置发射的时间为[56,63,70,77,84,91,98,105,112][ 56,63,70,77,84,91,98,105,112 ][56,63,70,77,84,91,98,105,112];
在[56,64,72,80,88,96,104,112][ 56,64,72,80,88,96,104,112 ][56,64,72,80,88,96,104,112]时从第二个装置发射的烟花。
解题思路
照亮时间除以发射间隔即一个装置最多同时存在的烟花数量,由于发射时也算同时存在,所以要额外加2。
题解
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <list>
#include <bitset>
#include <cmath>
#define endl '\n'
#define ft first
#define sd second
#define yes std::cout<<"Yes\n"
#define no std::cout<<"No\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<string, ll> psl;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pss> vpss;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef queue <int> qi;
typedef queue <ll> ql;
typedef queue <pii> qpii;
typedef queue <pll> qpll;
typedef queue <psi> qpsi;
typedef queue <psl> qpsl;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef priority_queue<string> pqs;
typedef priority_queue<pii> pqpii;
typedef priority_queue<psi> pqpsi;
typedef priority_queue<pll> pqpl;
typedef priority_queue<psi> pqpsl;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<char, int> mci;
typedef map<char, ll> mcl;
typedef map<string, int> msi;
typedef map<string, ll> msl;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> uml;
typedef unordered_map<char, int> umci;
typedef unordered_map<char, ll> umcl;
typedef unordered_map<string, int> umsi;
typedef unordered_map<string, ll> umsl;
void cinv(vi vec,int n)
{
for (int i = 1; i <= (n); i++)
cin >> (vec)[i];
}
void rcinv(vi vec, int n)
{
for (int i = (n); i >= 1; i--)
cin >> (vec)[i];
}
void coutv(vi vec, int n)
{
for (int i = 1; i <= (n); i++)
cout << (vec)[i] << " ";
cout <<