1478A. Nezzar and Colorful Balls

看半天题,然后才发现是统计最大值。

int _;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
for (cin >> _; _--;) {
int n;
cin >> n;
vector<int> a(n + 1, 0);
for (int i = 0, x; i < n; ++i) cin >> x, a[x]++;
cout << *max_element(a.begin(), a.end()) << "\n";
}
return 0;
}

1478B. Nezzar and Lucky Number

int _;
int dp[1010];
bool f(int x, int d) {
while (x) {
if (x % 10 == d) return true;
x /= 10;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
for (cin >> _; _--;) {
int q, x, d;
cin >> q >> d;
vector<int> v(15, 1e9);
for (int i = 1; i <= 100; ++i) {
x = i % d;
if (f(i, d)) v[x] = min(v[x], i);
}
for (int i = 1; i <= q; ++i) {
cin >> x;
if (v[x % d] <= x)
cout << "YES\n";
else
cout << "NO\n";
}
}
return 0;
}

1478C. Nezzar and Symmetric Array

对d数组排个序,看一个每个出现的奇偶次数,其实 d 的顺序就是 a(绝对值) 的顺序对应过去的,两组应该是对称出现的。。

那可以按顺序求出对应的 a,要是求不出来或者出现重复,那么就失败,否则成功。

int _;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
for (cin >> _; _--;) {
int n;
cin >> n;
vector<ll> d(2 * n);
for (auto& x : d) cin >> x;
sort(d.rbegin(), d.rend()); // 注意这里是逆排
bool yn = 1;
ll sum = 0;
for (int i = 2; i < 2 * n; i += 2)
if (d[i] == d[i - 1]) yn = 0; for (int i = 0; i < n && yn; i++) {
if (d[2 * i] != d[2 * i + 1]) {
yn = 0;
break;
}
if ((d[2 * i] - sum) <= 0 or (d[2 * i] - sum) % (n - i) != 0) {
yn = 0;
break;
}
ll cur = (d[2 * i] - sum) / (n - i);
if (cur & 1) {
yn = 0;
break;
}
sum += cur;
}
cout << (yn ? "YES\n" : "NO\n");
}
return 0;
}

1478D. Nezzar and Board

\(2*x−y\) x想成 \(x + x − y\) ,也就是x加上x 和y的差值,这个差值可以是正的也可以是负的。执行完之后我们可以对新的数字继续增加这个差值,所以我们就可以根据两个数字得出一个等差数列。数列内的数字都可以倍包含在数组a里。

而我们的目的是找出一个最小的差值 \(d\),然后分别比对每一个 \(a[i]\)看是否可以由 \(a[i]\)和若干个 \(d\) 得到 k。先对 a 数组排个序,然后对所有的$ a[ i ]− a[ i − 1] $求 gcd,就得出了那个最小的差值 d。

// RioTian 21/01/29
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int _, n;
ll k;
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
for (cin >> _; _--;) {
cin >> n >> k;
vector<ll> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a.begin() + 1, a.end()); ll tmp = a[2] - a[1];
for (int i = 2; i < n; i++) tmp = gcd(tmp, a[i + 1] - a[i]); ll x = llabs(a[1] - k);
cout << (x % tmp == 0 ? "YES\n" : "NO\n");
}
return 0;
}

Codeforces #698 Div.2 (A~D题)个人题解记录的更多相关文章

  1. Codeforces #698 (Div. 2) E. Nezzar and Binary String 题解

    中文题意: 给你两个长度为 \(n\) 的01串 \(s,f,\)有 \(q\) 次询问. 每次询问有区间 \([\ l,r\ ]\) ,如果 \([\ l,r\ ]\) 同时包含\(0\)和\(1\ ...

  2. Codeforces#441 Div.2 四小题

    Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...

  3. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  4. Codeforces #344 Div.2

    Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...

  5. Codeforces #345 Div.1

    Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...

  6. codeforces #592(Div.2)

    codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...

  7. codeforces #577(Div.2)

    codeforces #577(Div.2) A  Important Exam A class of students wrote a multiple-choice test. There are ...

  8. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

  9. Codeforces 828B Black Square(简单题)

    Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...

  10. Codeforces Beta Round #27 (Codeforces format, Div. 2)

    Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...

随机推荐

  1. [UOJ#748] [UNR#6 1B] 机器人表演

    在这个科技发达的年代,真人表演已经落伍了.参加完 UOI 后,hehe 蚤去到了下山市大剧院,观看下山市最火爆的机器人表演. 机器人有时比人类更能抓住事情的本质.所谓表演,其实也就是开场有若干个机器人 ...

  2. [ABC263E] Sugoroku 3

    Problem Statement There are $N$ squares called Square $1$ though Square $N$. You start on Square $1$ ...

  3. [ABC262A] World Cup

    Problem Statement A sport event is held in June of every year whose remainder when divided by $4$ is ...

  4. Python实现贪吃蛇大作战

    贪吃蛇 初始版本 初始版本,只存在基本数据结构--双向队列. 游戏思路 贪吃蛇通过不断得吃食物来增长自身,如果贪吃蛇碰到边界或者自身则游戏失败. 食物是绿色矩形来模拟,坐标为随机数生成,定义一个蛇长变 ...

  5. FOJ有奖月赛-2015年11月 Problem A

    Problem A 据说题目很水 Accept: 113    Submit: 445Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem ...

  6. Oracle参数文件spfile

    spfile:server parameter file. spfile只能通过OEM(oracle enterprise manager)软件或者alter system命令进行修改. spfile ...

  7. ElasticSearch之cat indices API

    命令样例如下: curl -X GET "https://localhost:9200/_cat/indices?v=true&pretty" --cacert $ES_H ...

  8. 从零玩转设计模式之外观模式-waiguanmos

    title: 从零玩转设计模式之外观模式 date: 2022-12-12 15:49:05.322 updated: 2022-12-23 15:34:40.394 url: https://www ...

  9. Python——第一章:注释、变量、常量

    python中的注释有2种: 1.单行注释 单行注释用# #这是一个单行注释 快捷键用Ctrl+/全选多个内容可以多行快速注释,也可以快速去掉注释符# 比如快速将全选的所有行注释掉--加# 2.多行注 ...

  10. Windows 无法加载这个硬件的设备驱动程序。驱动程序可能已损坏或不见了。 (代码 39)

    哔站中有视频解决方案,可以直观看如何操作:Windows 无法加载这个硬件的设备驱动程序.驱动程序可能已损坏或不见了. (代码 39) 第一步:明确感叹号故障硬件(我的是蓝牙也可以是别的)--右键&q ...