contest
A
#include <iostream>
using namespace std;
int T;
string week[6] = {"0","Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
int main()
{
long long y1, m1, d1,
y2 ,m2, d2,
cnt, mod, date, fn;
string first, second;
cin >> T;
while(T--)
{
cin >> y1 >> m1 >> d1 >> first >> y2 >> m2 >> d2;
for(int i = 1;i < 6;i++)
{
if(first == week[i])
{
date = i;
}
}
cnt = (y2 - y1) * 360 + (m2 - m1) * 30 + (d2 - d1);
mod = cnt % 5;
if(mod + date < 5 && mod + date > 0)
{
cout << week[mod + date] << endl;
}
else if(mod + date <= 0)
{
cout << week[mod + date + 5] << endl;
}
else
{
if((mod + date) % 5 == 0)
cout << week[5] << endl;
else
cout << week[(mod + date) % 5] << endl;
}
}
return 0;
}
B
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
int main()
{
int T;
ll n, k;
string sequence;
cin >> T;
while(T--)
{
ll maxans = 0, tempx = 0, tempy = 0, tempans = 0;
cin >> n >> k >> sequence;
for(int i = 0;i < n;i++)
{
if(sequence[i] == 'U')
{
tempy++;
}
if(sequence[i] == 'D')
{
tempy--;
}
if(sequence[i] == 'L')
{
tempx--;
}
if(sequence[i] == 'R')
{
tempx++;
}
tempans = abs(tempx) + abs(tempy);
if(tempans > maxans)
{
maxans = tempans;
}
}
tempx *= (k - 1);
tempy *= (k - 1);
for(int i = 0;i < n;i++)
{
if(sequence[i] == 'U')
{
tempy++;
}
if(sequence[i] == 'D')
{
tempy--;
}
if(sequence[i] == 'L')
{
tempx--;
}
if(sequence[i] == 'R')
{
tempx++;
}
tempans = abs(tempx) + abs(tempy);
if(tempans > maxans)
{
maxans = tempans;
}
}
cout << maxans << endl;
}
return 0;
}
C
#include <iostream>
using namespace std;
typedef long long ll;
ll buckets[100001] = {0};
int main()
{
int T, n;
cin >> T;
while(T--)
{
ll sum = 0, cnt = 0;
cin >> n;
for(int i = 0;i < n;i++)
{
cin >> buckets[i];
sum += buckets[i];
}
sum /= n;
for(int i = 0;i < n;i++)
{
if(buckets[i] > sum)
{
cnt += buckets[i] - sum;
}
}
cout << cnt << endl;
}
return 0;
}
D
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
ll n,
k;
int T;
cin >> T;
while(T--)
{
cin >> n >> k;
if(n == 0)
{
cout << 0 << endl;
continue;
}
for(int i = 0;i < k;i++)
{
if(n % 2 == 0)
n /= 2;
else
{
if(n == 1)
break;
n = n / 2 + 1;
}
}
cout << n << endl;
}
return 0;
}
E
#include <iostream>
using namespace std;
int main()
{
int T,
k,
n,
m,
u,
v,
maxt;
string peo;
cin >> T;
while(T--)
{
cin >> k >> peo >> n >> m;
for(int i = 0;i < m;i++)
cin >> u >> v;
maxt = (m - (n - 1)) % k;
if(peo[maxt] == '1')
cout << 2 << endl;
else
cout << 1 << endl;
}
return 0;
}