首页 > 其他分享 >「解题报告」Codeforces Round 886 (Div. 4)

「解题报告」Codeforces Round 886 (Div. 4)

时间:2023-07-22 10:34:08浏览次数:46  
标签:ch 886 read Codeforces long yifan while Div getchar

比赛地址:Dashboard - Codeforces Round 886 (Div. 4) - Codeforces

由于时间太晚了,因此并没有参加比赛,题目都是后来补做的。

A. To My Critics

Problem - A - Codeforces

\(T\) 组数据,有 \(a, b, c\) 三个数,判断是否存在两个数的和 \(sum \ge 10\)。

/*
  The code was written by yifan, and yifan is neutral!!!
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

void solve() {
    int a = read<int>(), b = read<int>(), c = read<int>();
    if (a + b >= 10 || b + c >= 10 || a + c >= 10) {
        puts("Yes");
    } else {
        puts("No");
    }
}

int main() {
    int T = read<int>();
    while (T --) {
        solve();
    }
    return 0;
}

B. Ten Words of Wisdom

Problem - B - Codeforces

\(T\) 组数据,有 \(n\) 个人,每个人有一个反应,第 \(i\) 个人的反应长度为 \(a_i\),质量为 \(b_i\)。现在求出长度小于等于 \(10\) 的质量最高的人的编号。

/*
  The code was written by yifan, and yifan is neutral!!!
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

int n, a, b;

void solve() {
    n = read<int>();
    int mx = 0, pos = 0;
    for (int i = 1; i <= n; ++ i) {
        a = read<int>(), b = read<int>();
        if (a <= 10) {
            if (b > mx) {
                mx = b;
                pos = i;
            }
        }
    }
    cout << pos << '\n';
}

int main() {
    int T = read<int>();
    while (T --) {
        solve();
    }
    return 0;
}

C. Word on the Paper

Problem - C - Codeforces

有一个 \(8 \times 8\) 的网格图,有一个单词在网格图中从上写到下,询问这个单词。

/*
  The code was written by yifan, and yifan is neutral!!!
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

char c;
char str[10];

void solve() {
    memset(str, '\0', sizeof str);
    int l = 0;
    for (int i = 1; i <= 8; ++ i) {
        for (int j = 1; j <= 8; ++ j) {
            cin >> c;
            if (c >= 'a' && c <= 'z') {
                str[l ++] = c;
            }
        }
    }
    cout << str << '\n';
}

int main() {
    int T = read<int>();
    while (T --) {
        solve();
    }
    return 0;
}

D. Balanced Round

Problem - D - Codeforces

有 \(n\) 个数,还有一个整数 \(k\),现在这 \(n\) 个数可以随便排序,也可以从这 \(n\) 个数中删去一些数,问最少删多少个数,可以使得剩下的数两两之间差的绝对值小于等于 \(k\)。

转化一下,根据相邻两个数之间的差的绝对值大于 \(k\),可以将这 \(n\) 个数分成若干段区间,求长度最大的区间,最后用 \(n\) 减去这个最大区间的长度即可。

/*
  The code was written by yifan, and yifan is neutral!!!
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

const int N = 2e5 + 5;

int n, k;
int g[N];
vector<int> pos;

void solve() {
    pos.clear();
    n = read<int>(), k = read<int>();
    for (int i = 1; i <= n; ++ i) {
        g[i] = read<int>();
    }
    sort(g + 1, g + n + 1);
    pos.emplace_back(1);
    for (int i = 2; i <= n; ++ i) {
        if (g[i] - g[i - 1] > k) {
            pos.emplace_back(i);
        }
    }
    pos.emplace_back(n + 1);
    int siz = pos.size(), mx = -1;
    for (int i = 1; i < siz; ++ i) {
        mx = max(mx, pos[i] - pos[i - 1]);
//        cout << pos[i] - pos[i - 1] << '\n';
    }
    cout << (mx == -1 ? n : n - mx) << '\n';
}

int main() {
    int T = read<int>();
    while (T --) {
        solve();
    }
    return 0;
}

E. Cardboard for Pictures

Problem - E - Codeforces

有 \(n\) 个正方形,现在给每个正方形的边长加上 \(2w\),使得总面积为 \(c\),求 \(w\)。

一开始想的解方程,结果怎么着都避免不了爆 long long ,后来在旁边的大佬的提醒下用了二分。

/*
  The code was written by yifan, and yifan is neutral!!!
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

const int N = 2e5 + 5;

int n;
ll c, sum;
ll d[N];

int check(ll w) {
    sum = 0;
    for (int i = 1; i <= n; ++ i) {
        sum += (d[i] + 2 * w) * (d[i] + 2 * w);
        if (sum > c)    return false;
    }
    return true ;
}

void solve() {
    n = read<int>(), c = read<ll>();
    for (int i = 1; i <= n; ++ i) {
        d[i] = read<ll>();
    }
    ll l = 1, r = 1e9, ans = 0;
    while (l <= r) {
        ll mid = (l + r) >> 1;
        if (check(mid)) {
            l = mid + 1;
            ans = mid;
        } else {
            r = mid - 1;
        }
    }
    cout << ans << '\n';
}

int main() {
    int T = read<int>();
    while (T --) {
        solve();
    }
    return 0;
}

F. We Were Both Children

Problem - F - Codeforces

暴力跳即可,相信看到这里的聪明的你一定可以看懂。

/*
  The code was written by yifan, and yifan is neutral!!!
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template<typename T>
inline T read() {
	T x = 0;
	bool fg = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		fg |= (ch == '-');
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 3) + (x << 1) + (ch ^ 48);
		ch = getchar();
	}
	return fg ? ~x + 1 : x;
}

const int N = 2e5 + 5;

int n;
int d[N], in[N];

void solve() {
	n = read<int>();
	for (int i = 1; i <= n; ++ i) {
		d[i] = in[i] = 0;
	}
	for (int i = 1, x; i <= n; ++ i) {
		x = read<int>();
		if (x <= n) {
			++ in[x];
		}
		d[i] = 0;
	}
	for (int i = 1; i <= n; ++ i) {
		for (int j = i; j <= n; j += i) {
			d[j] += in[i];
		}
	}
	cout << *max_element(d + 1, d + n + 1) << '\n';
}

int main() {
	int T = read<int>();
	while (T --) {
		solve();
	}
	return 0;
}

到此为止了。

标签:ch,886,read,Codeforces,long,yifan,while,Div,getchar
From: https://www.cnblogs.com/yifan0305/p/17572944.html

相关文章

  • Codeforces 1456E - XOR-ranges
    考虑一个\(L\lex\leR\)的数\(x\),必然是一段前缀贴着\(L\)或者\(R\),然后下一位脱离了\(L\)和\(R\)的限制,后面随便乱填。注意到一个性质,对于某一位\(d\),考虑这一位上没有限制的那些位置,最优方案肯定是令其等于其左边(或者右边)第一个有限制的数的第\(d\)位上的值。这......
  • Codeforces Round 886 (Div. 4)
    A.ToMyCritics#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve(){vector<int>a(3);for(auto&i:a)cin>>i;sort(a.begin(),a.end());if(a[2]+a[1]>=10)cout......
  • Codeforces 1830E - Bully Sort
    这种题肯定首先要寻找不变量。显然后面排好序的后缀不会被改变。因此从整体上来看我们的流程肯定是,如果当前\(p_n=n\),就令\(n\)减一,否则你一步换的\(i\)肯定满足\(p_i=n\)。而显然\(\min\limits_{j=i}^np_j\lei\),因此我们考察\(\sum|i-p_i|\)和\(\sum\limits_{i<j}[p_......
  • Codeforces 794G - Replace All
    一个比较垃圾的做法,卡着时限过了这道题。首先大胆猜个结论:要么\(|s|=|t|\),此时\(A,B\)任取,要么存在字符串\(c\)和整数\(x,y\)使得\(A=c^x,B=c^y\),其中\(c^x\)表示\(x\)个\(c\)拼接得到的结果。证明的话感觉还挺复杂的,可能要border引理之类的东西,不过我是先写了个......
  • 洛谷 P8861 - 线段
    牛逼题。先考虑\(l\le10^5,10^5+1\ler\)的部分分:一种方法是线段树,即因为左右端点是独立的,因此对左右端点各维护一个权值线段树表示有多少个区间以这个值为左/右端点,这样对于修改,左端点的部分相当于先查询\(\lel\)的数的个数,然后将它们都挂到\(l\)上,最后把\(<l\)的部......
  • Vue3 响应式全局对象json 动态绑定界面三 (Div块样式 字符串叠加)
    效果 man.js  定义响应式全局对象 globalData//全局对象constglobalData=reactive({missedCallData:"",currentUserTel:"",})app.provide('globalData',globalData);在main.js的函数中改变missedCallData 的值从而改变界面列表//改变全局变量gl......
  • Vue3 响应式全局对象json 动态绑定界面四 (Div块样式 Json数据绑定)
    效果man.js  定义响应式全局对象 globalData//全局对象constglobalData=reactive({extTelTalkData:[{userExten:"1000",userName:"刘亦菲",callStatus:"通话"},{......
  • Codeforces 856F - To Play or not to Play
    首先,DP肯定是逃不掉的,因为直接贪心其实不好判断在两个人都可以上线的时间段究竟是哪个人上线,需要通过后面的情况来做出判断,但是这题值域比较大直接维护DP值肯定不行,因此考虑先设计一个与值域有关的DP然后优化。将时间区间离散化,然后依次考虑每个时间区间。一个很自然的想法......
  • Codeforces Round div.2 C
    Smiling&Weeping----我对姑娘的喜欢,何止钟意二字题目链接:Problem-C-Codeforces自我分析:我感觉这是一道很有意义的题目,可以帮我们更好的理解二进制的本质思路:首先先了解一下题目,我们是求由第i个数到末尾的异或和(异或:相同为0,不同为1),那么我......
  • Codeforces Round 882 div.2 B
    Smiling&Weeping----玫瑰花你拿才好看,风景要和你看才浪漫--<-<-<@B.HamonOdysseytimelimitpertest1secondmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputJonathanisfightingagainstDIO......