如果支付失败,那么最大值=之前支付成功的+这次想支付但失败的+25-1。
如果支付成功,那么最小值=之前所有支付成功的。
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
long long n, num;
char s[3];
scanf("%lld", &n);
long long l = 0, r = 10000000000000000, ans = 10000000000000000;
for (int i = 1; i <= n; i++)
{
scanf("%lld%s", &num, s);
if (s[0] == '-')
{
r = min(r, l + num + 25);
// r = l + num + 25;//不取min WA了,感觉是有不合法数据
}
else
{
l += num + 25;
}
ans = min(ans, r - l);
}
printf("%lld\n", ans);
}
return 0;
}
比赛时读错题了, the number that have a prime number of ones in their binary representation. 翻译成了一种二进制表示时是质数的数,应该是二进制表示中一的数量是质数的数…
AC代码:
int get(int x)
{
int res = 0;
while (x)
{
if (x % 2)
res++;
x /= 2;
}
return res;
}
int f(int x)
{
if (x == 0 || x == 1)
return 0;
for (int i = 2; i * i <= x; i++)
if (x % i == 0)
return 0;
return 1;
}
int ans[100010];
inline void pre()
{
for (int i = 1; i <= 100000; i++)
ans[i] = f(get(i)) ? ans[i - 1] + 1 : ans[i - 1];
}
int main()
{
pre();
int t;
cin >> t;
while (t--)
{
int l, r;
cin >> l >> r;
cout << ans[r] - ans[l - 1] << endl;
}
return 0;
}
ACPC Headquarters : AASTMT (Stairway to Heaven)
map set 搞一搞,加各种标记优化~
struct node
{
int L, R;
map<string, int> mp;
} comp[110];
inline bool f(int l1, int r1, int l2, int r2)
{
if (l1 == l2 || l1 == r2 || r1 == l2 || r1 == r2)
return 1;
if (l1 > l2 && l1 < r2)
return 1;
if (r1 > l2 && r1 < r2)
return 1;
if (l1 < l2 && r1 > r2)
return 1;
return 0;
}
set<string> ans;
set<string> vis;
char s[100];
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, l, r, m;
scanf("%d", &n);
ans.clear();
vis.clear();
for (int i = 1; i <= n; i++)
{
comp[i].mp.clear();
scanf("%s%d%d%d", s, &comp[i].L, &comp[i].R, &m);
for (int j = 1; j <= m; j++)
{
scanf("%s", s);
comp[i].mp[s] = 1;
}
for (auto it = comp[i].mp.begin(); it != comp[i].mp.end(); it++)
{
if (ans.count(it->first) || !vis.count(it->first))
continue;
for (int j = 1; j < i; j++)
{
if (f(comp[i].L, comp[i].R, comp[j].L, comp[j].R))
{
for (auto it2 = comp[j].mp.begin(); it2 != comp[j].mp.end(); it2++)
{
if (it->first == it2->first)
{
ans.insert(it2->first);
}
}
}
}
}
for (auto it = comp[i].mp.begin(); it != comp[i].mp.end(); it++)
vis.insert(it->first);
}
printf("%d\n", ans.size());
for (auto it = ans.begin(); it != ans.end(); it++)
printf("%s\n", (*it).c_str());
}
return 0;
}