还是div4写起来爽
Dashboard - Codeforces Round 886 (Div. 4) - Codeforces
题意:
给出三个数a,b,c问是否存在两个数相加大于10
题解:
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
typedef pair PII;
const LL N = 2e5 + 10, MOD = 998244353, INF = 0x3f3f3f3f;
void solve()
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if (a + b >= 10 || a + c >= 10 || b + c >= 10)
printf("YES\n");
else
printf("NO\n");
}
int main()
{
int T = 1;
scanf("%d", &T);
while (T--)
{
solve();
}
return 0;
}
题意:
有n对ai,bi问在ai<=10的前提下最大的bi
题解:
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
typedef pair PII;
const LL N = 2e5 + 10, MOD = 998244353, INF = 0x3f3f3f3f;
void solve()
{
int n, ans = 0, t = -1;
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
{
int a, b;
scanf("%d%d", &a, &b);
if (a <= 10 && b > t)
ans = i, t = b;
}
printf("%d\n", ans);
}
int main()
{
int T = 1;
scanf("%d", &T);
while (T--)
{
solve();
}
return 0;
}
题意:
看样例就能看出来...,在8*8的矩阵里有一个竖着的英文单词,输出它
题解:
写法贼多
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
typedef pair PII;
const LL N = 2e5 + 10, MOD = 998244353, INF = 0x3f3f3f3f;
void solve()
{
for (int i = 1; i <= 8; ++i)
{
char ch[10], c = '.';
scanf("%s", ch + 1);
for (int j = 1; j <= 8; ++j)
{
if (ch[j] != '.')
c = ch[j];
}
if (c != '.')printf("%c", c);
}
printf("\n");
}
int main()
{
int T = 1;
scanf("%d", &T);
while (T--)
{
solve();
}
return 0;
}
题意:
给出n个数ai和一个k,问删掉最少多少个数之后,将数组排序后能使得相邻元素之间差值不大于k
题解:
直接排序然后求一个相邻元素之间差值不大于k的最大区间长度d,n-d即为答案
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
typedef pair PII;
const LL N = 2e5 + 10, MOD = 998244353, INF = 0x3f3f3f3f;
int a[N];
void solve()
{
int n, k, maxx = 1;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
for (int i = 2, t = 1; i <= n; ++i)
{
if (a[i] - a[i - 1] > k)t = 1;
else ++t;
maxx = max(maxx, t);
}
printf("%d\n", n - maxx);
}
int main()
{
int T = 1;
scanf("%d", &T);
while (T--)
{
solve();
}
return 0;
}
题意:
给出n个数si和一个c,求使得 的w
题解:
二分(可能也能直接解二元一次方程?)。注意别爆long long就行
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
typedef pair PII;
const LL N = 2e5 + 10, MOD = 998244353, INF = 0x3f3f3f3f;
LL n, c, a[N];
bool get_sum(LL d)
{
LL s = 0;
for (int i = 1; i <= n; ++i)
{
s += (a[i] + 2 * d) * (a[i] + 2 * d);
if (s > c)return 0;
}
return 1;
}
void solve()
{
scanf("%lld%lld", &n, &c);
for (int i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
LL l = 0, r = 6e8;
while (l < r)
{
int mid = l + r + 1 >> 1;
if (get_sum(mid))
l = mid;
else
r = mid - 1;
}
printf("%lld\n", l);
}
int main()
{
int T = 1;
scanf("%d", &T);
while (T--)
{
solve();
}
return 0;
}
题意:
有n只青蛙,每只青蛙初始都在0位置,每秒会往前跳ai。你可以在位置1到n设置一个陷阱,陷阱会抓住经过它的所有青蛙,求你最多能抓住多少青蛙。
题解:
在位置i放置陷阱能抓住所有跳跃距离是i的因数的青蛙,对所有跳跃距离在n以下的青蛙进行计数,枚举在1到n放置陷阱的情况,对于每种情况分解因数一下就能求能抓住的青蛙数。
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
typedef pair PII;
const LL N = 2e5 + 10, MOD = 998244353, INF = 0x3f3f3f3f;
int cnt[N];
void solve()
{
int n, ans = 0;
scanf("%d", &n);
memset(cnt, 0, sizeof cnt);
for (int i = 1, x; i <= n; ++i)
{
scanf("%d", &x);
if (x <= n)cnt[x]++;
}
for (int i = 1; i <= n; ++i)
{
int s = 0;
for (int j = 1; j * j <= i; ++j)
{
if (i % j == 0)
{
s += cnt[j];
if (j * j != i)
s += cnt[i / j];
}
}
ans = max(ans, s);
}
printf("%d\n", ans);
}
int main()
{
int T = 1;
scanf("%d", &T);
while (T--)
{
solve();
}
return 0;
}
题意:
给出n个坐标xi,yi。有一个指南针它会指向磁石,并且它只能指向正东、正南、正西、正北以及正东南、正西南、正东北、正西北,如果它的指向不是以上八个方向,它就会坏掉。问最多有多少种方案:将磁石与指南针放到两个不同的坐标使得指南针能正常工作。
题解:
正常工作的情况:两个坐标x值相等( — ),y值相等( | ),x+y相等( \ ),x-y相等( / ),开四个map分别存x,y,x+y,x-y计数即可(一种做法见代码)
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
#include
题意:
有n个人,给出m对关系ai,bi,di:ai在bi前方di距离处(di<0说明ai在bi后方)。
问能否存在一种方案能够同时满足这m对关系
题解:
写的带权并查集...感觉挺板子的。维护并查集的同时维护x距离x的根(祖先)的距离,遍历所有关系,满足则加入并查集,不满足输出NO直接return(写过食物链的话应该挺容易想到这个的)
看了眼题目的tag发现还能建图然后dfs判断...
乐,H被hack了,明天再补代码。原来是爆int被逮住了...
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
#include