首页 > 其他分享 >D. Strong Vertices

D. Strong Vertices

时间:2023-10-03 14:34:48浏览次数:26  
标签:int LL Vertices long solve Strong

D. Strong Vertices
条件转移一下即可
由a[u]−a[v]≥b[u]−b[v],可得a[u]-b[u]>=a[v]-b[v]。
设c[i]=a[i]-b[i],由题意得只要c[i]>=cj,点i就有指向j的路。
因此题目就转化成:求c数组中最大元素的个数及其位置。

点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 2e5 + 10;
LL a[N],b[N],q[N];
void solve() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	LL mx = -1e11;
	for (int i = 1; i <= n; i++) a[i] = a[i] - b[i], mx = max(mx, a[i]);
	int ans = 0;
	for (int i = 1; i <= n; i++) if (a[i] == mx) q[++ans]=i;
	cout << ans<<'\n';
	for (int i = 1; i <= ans; i++) cout << q[i] << ' ';
	cout << '\n';
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

标签:int,LL,Vertices,long,solve,Strong
From: https://www.cnblogs.com/bu-fan/p/17741112.html

相关文章

  • [React Typescript] Strongly type Shared props for multiple components (React.FC<
    import{Equal,Expect}from"../helpers/type-utils";typeInputProps=React.ComponentProps<"input">;constCOMPONENTS={text:(props)=>{return<input{...props}type="text"/>;},number:(p......
  • [React Typescript] Strongly type Render prop
    1.React.ReactNodeimport{useState}from"react";import{createPortal}from"react-dom";import{Equal,Expect}from"../helpers/type-utils";interfaceModalChildProps{isOpen:boolean;openModal:()=>void;......
  • [React Typescript] Strongly Typing Lazy Loaded Components with Generics
    Navigatingtothetypedefinitionfor lazy by CMD+click inlocalVSCode,orinthe DefinitelyTyped repo.Wecanseethefollowingdefinition:functionlazy<TextendsComponentType<any>>( factory:()=>Promise<{default:T}>):L......
  • Codeforces 1857D:Strong Vertices 与图论无关的出度最大统计
    1857D.StrongVerticesDescription:给定两个长度均为\(n\)的数组\(a\)和\(b\)(编号\(1\)~\(n\)),如果\(a_u-a_v\geqb_u-b_v\)\((u\neqv)\),那么从\(u\)到\(v\)建立一条有向边。"Strong"定义为:一个点\(V\)可以经过有向图中合法的通路到达其他所有的点。请求解出"......
  • Educational 151 DIV2 T3 strong password
    T3strongpassword就是对于输入的每一个\(l,r\),我们遍历\(s[l]~s[r]\),对于每次遍历,我们设置一个临时指针\(cur\),然后通过指针右移寻找所需要的值在外面我们弄两个指针,分别代表每次遍历\([l,r]\)的区间的指针\(nmx\)和全局指针\(mx\)我们用临时指针更新单次区间的......
  • [ARC162D] Smallest Vertices
    [ARC162D]SmallestVerticesAtcoder:[ARC162D]SmallestVertices洛谷:[ARC162D]SmallestVerticesProblem在本问题中,当我们提到有根有向树时,我们指的是所有边都指向从根到叶子的有根树。给定一个使得其总和为\(N-1\)的非负整数序列\(d=(d_1,d_2,\ldots,d_N)\)。对于带编......
  • Strong Password(贪心思想)
    StrongPasswordtimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputMonocarpfinallygotthecouragetoregisteronForceCoders.Hecameupwithahandlebutisstillthinkingaboutthepassw......
  • Educational Codeforces Round 151 (Rated for Div. 2) C. Strong Password
    题目翻译,给定t组数据,每组数据包含一个字符串s,两个长度为m的字符串l和r,要求判断是否存在一个长度为m的字符串res,满足l[i]<=res[i]<=r[i](i->0~m)且不是s的子序列贪心首先对于所有满足l<res<r的字符串,我们只需判断是否存在一个字符串不是子序列即可,那么我们让res成为子序列的可能......
  • CodeForces 1845C Strong Password
    洛谷传送门CF传送门我怎么这么多天没写题解了,快来水一篇。考虑对\(s\)串建子序列自动机后dp。设\(n=|s|\)。建子序列自动机,就是求出\(nxt_{i,j}\)为\([i,n]\)中第一个等于\(j\)的位置,不存在则\(nxt_{i,j}=n+1\)。然后我们设\(f_{i,j}\)为填到密码的......
  • CF1845C Strong Password
    思路这场edu爆炸了,特此记录。由于\(m\le10\),因此可以直接考虑搜索。对于定义状态为\((idx,cur)\),表示当前在填密码的第\(idx\)位,且使用了\(s\)中的前\(cur\)个字符。首先注意到对于同一个数字,如果其在\(s\)中出现了不止一次,那么出现在前边的显然比出现在后边的潜......