tcl的题解
1.ovo的崇拜者
题解:
数据量小,直接暴力跑就好了。
2.The Richest Lolita
题解:
很明显这题的答案就是最大的(m-9)个元素之和。
输入的时候把所有元素加起来,把最小的九个元素存起来。
之后用总和减去九个元素就得到答案了。
不能开数组把所有元素都存起来,会mle。
数据范围,总和注意用long long。
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
int main()
{
int n;
cin >> n;
while (n--)
{
int m, x;
cin >> m;
ll ans = 0;
multiset<int>s;
for (int i = 0; i < 9; i++)
{
cin >> x;
ans += x;
s.insert(x);
}
for (int i = 0; i < m - 9; i++)
{
cin >> x;
ans += x;
if (s.lower_bound(x) != s.end())
{
auto it = s.end();
it--;
s.erase(it);
s.insert(x);
}
}
for (auto p : s)
{
ans -= p;
}
cout << ans << endl;
}
return 0;
}
3.家庭成员
题解:
还没写
4.多才多艺的同学们
题解:
位运算。
不会的可以用字符串一位一位存。
#include<iostream>
using namespace std;
const int MAXN = 100008;
int a[MAXN];
int main()
{
int n, m, T, x, p;
cin >> T;
while (T--)
{
cin >> m;
for (int i = 0; i < m; i++)
{
a[i] = 0;
cin >> n;
while (n--)
{
cin >> x;
a[i] |= 1 << x;
}
}
cin >> p;
for (int i = 0; i < p; i++)
{
int tmp = 0, ans = 0;
cin >> n;
while (n--)
{
cin >> x;
tmp |= 1 << x;
}
for (int j = 0; j < m; j++)
{
ans += (tmp & a[j]) == tmp;
}
if (i)
{
cout << " ";
}
cout << ans;
}
cout << endl;
}
return 0;
}
5.彩礼和嫁妆
题解:
模拟题,暴力模拟就好了。
注意退出条件是当前转账金额等于上一次的转账金额。
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
int a, b, x, z, y;
cin >> a >> b >> x >> z;
y = x * z / 100;
bool f = true;
while (f)
{
int ta = a, tb = b;
if (x != 0 && a >= x)
{
a -= x;
b += x;
y = x * z / 100;
}
else
{
f = false;
break;
}
if (y != 0 && b >= y)
{
b -= y;
a += y;
x = y * z / 100;
y = x * z / 100;
}
else
{
f = false;
break;
}
if (ta == a && tb == b)
{
cout << "Endless loop" << endl;
break;
}
}
if (!f)
{
cout << a << " " << b << endl;
}
}
return 0;
}
6.纪念日
题解:
直接上代码吧。
#include<iostream>
using namespace std;
int s[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
bool isLeapYear(int year)
{
if (year % 400 == 0 && year % 3200 != 0
|| year % 100 != 0 && year % 4 == 0)
{
return true;
}
return false;
}
int y, m, d;
void increase(int day)
{
while (day--)
{
d++;
if (m == 12)
{
if (d > 31)
{
d = 1;
m = 1;
y++;
}
}
else
{
if (isLeapYear(y))
{
s[2] = 29;
}
else
{
s[2] = 28;
}
if (d > s[m])
{
m++;
d = 1;
}
}
}
cout << y << " " << m << " " << d << endl;
}
int main()
{
int n;
cin >> n;
while (n--)
{
cin >> y >> m >> d;
increase(1314);
}
return 0;
}
感谢观看~~~