首页 > 其他分享 >CF1825 div 2

CF1825 div 2

时间:2023-05-08 23:12:43浏览次数:33  
标签:int Codeforces long cin CF1825 Limit https div

A

结论题 删掉一个或者全相同。

// Problem: A. LuoTianyi and the Palindrome String
// Contest: Codeforces - Codeforces Round 872 (Div. 2)
// URL: https://codeforces.com/contest/1825/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

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

void work(){
	string s;
	cin>>s;
	// cout<<s<<endl;
	int n=s.length();
	s='_'+s;
	int fg=0;
	for(int i=1;i<=n;i++)
	if(s[i]!=s[1]) {fg=1;}
	cerr<<n<<endl;
	if(fg)cout<<n-1<<endl; 
	else cout<<-1<<endl;
}
int main(){
	int T;
	cin>>T;
	while(T--){
		work();
	}
	
	return 0;
}

B

结论题,考虑左上角放极差

// Problem: A. LuoTianyi and the Palindrome String
// Contest: Codeforces - Codeforces Round 872 (Div. 2)
// URL: https://codeforces.com/contest/1825/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[20005];
void work(){
	int n,m;
	cin>>n>>m;
	
	int nn=n*m;
	for(int i=1;i<=nn;i++)cin>>a[i];
	sort(a+1,a+nn+1);
	int ans=(a[nn]-a[1])*(nn-1);
	
	ans-=(min(n,m)-1)*min(a[nn]-a[nn-1],a[2]-a[1]);
	cout<<ans<<endl;
}
signed main(){
		ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T;
	cin>>T;
	while(T--){
		work();
	}
	
	return 0;
}

C

考虑是从一个点开始然后左右延伸。然后枚举 贪心。

// Problem: C. LuoTianyi and the Show
// Contest: Codeforces - Codeforces Round 872 (Div. 2)
// URL: https://codeforces.com/contest/1825/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N],n,m;
int cnt[N],c1,c2,num;
void work(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	c1=c2=0,num=0;;
	for(int i=1;i<=n;i++){
		if(a[i]==-1) c1++;
		else if(a[i]==-2) c2++;
		else {
			if(cnt[a[i]]==0) num++;
			cnt[a[i]]++;
		}
	}
	// cout<<c1<<" "<<c2<<" "<<num<<endl;
	int ans=max(c1,c2)+num;
	int ccc=0;
	for(int i=1;i<=m;i++){
		if(cnt[i]){
			ccc++;
			int tmp=min(i,ccc+c1)+min(m-i,num-ccc+c2);
			// cout<<min(i,ccc+c1)<<" "<<min(m-i-1,num-ccc+c2)<<endl;
			ans=max(ans,tmp);
		}
	}
	cout<<min(ans,m)<<endl;
	for(int i=1;i<=n;i++) if(a[i]>0)cnt[a[i]]=0;
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int T;
	cin>>T;
	while(T--){
		work();
	}
	
	return 0;
}

D1

操!
没取模。

// Problem: D1. LuoTianyi and the Floating Islands (Easy Version)
// Contest: Codeforces - Codeforces Round 872 (Div. 2)
// URL: https://codeforces.com/contest/1825/problem/D1
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
const long long N=4e5+5,mod=1e9+7;
long long n,k;
vector<long long> v[N];
long long siz[N],ans;

void dfs(long long u,long long fa){
	siz[u]=1;
	for(long long x:v[u]){
		if(x==fa) continue;
		dfs(x,u);
		siz[u]+=siz[x];
		ans+=(long long)siz[x]*(n-siz[x])%mod;
		ans%=mod;
	}
	
}
long long qp(long long a,long long b){
	long long ret=1;
	for(;b;b>>=1,a=a*a%mod) if(b&1) ret=ret*a%mod;
	return ret;
}
signed main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>k;
	if(k==1||k==3){cout<<1<<endl;return 0;}
	for(long long i=1;i<n;i++){
		long long x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1,0);
	// cerr<<ans<<endl;
	ans=(ans+n*(n-1)/2)%mod;
	printf("%lld\n",(long long)ans*qp(n*(n-1)/2%mod,mod-2)%mod);
	return 0;
}

标签:int,Codeforces,long,cin,CF1825,Limit,https,div
From: https://www.cnblogs.com/Artemis-lx/p/17383460.html

相关文章

  • Codeforces Round 872 (Div. 1 & Div. 2)
    这场寄大了。Mypredictorsay-101pts。https://codeforces.com/contest/1824https://codeforces.com/contest/18252A.LuoTianyiandthePalindromeString因为给出的\(s\)是一个回文串,所以答案只可能是\(-1\)或者\(n-1\),只需要看一下删掉哪一个即可,然后判定,这些都......
  • CodeForces - 597A Divisibility (模拟)
    TimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-597ADivisibilitySubmit StatusDescriptionFindthenumberof k-divisiblenumbersonthesegment [a, b].Inotherwordsyouneedtofindthenumberofsuchintegerv......
  • Codeforces Round 871 (Div. 4)
    A.LoveStory#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintread(){intx=0,f=1,ch=getchar();while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if......
  • Codeforces Round 871 (Div. 4)
    A.LoveStory题意:给定n个长度为10的字符串,问其与codeforces字符串的对应下标字母不同的个数。分析:对于每个字符串从前往后依次和“codeforces”对应字符比较然后统计不同字母数即可code:#include<bits/stdc++.h>usingnamespacestd;intmain(){ std::ios::sync_wit......
  • CF R870 div.2
    C 输出"NO"的充要条件是要在最初就选择\(k\)个物品,使得\(k\midN\)。发现朴素做法是\(O(TM)\),可以对\(N\)的约数进行枚举,优化为\(O(T\sqrt(N))\),再特判\(N\leqM\)和\(N=1\)的情况。#include<bits/stdc++.h>usingnamespacestd;constintN=1e6+10;int......
  • 图片填满div,真让人头大
    家人们,这图片到底怎样才能完全填满div啊,想问度娘结果搜索的问题都乱七八糟的(怎么那么多问题QAQ),描述问题都描述不来具体问题如下:图片有自己的分辨率大小,例如宽100px,高100px,将图片添加到div中:<divclass="xx"><imgsrc="xxx"></div>接着用css代码编辑样式的时候,首先设置di......
  • Codeforces Round 871 (Div. 4)
    CodeforcesRound871(Div.4)A-LoveStory#include<bits/stdc++.h>usingnamespacestd;typedefpair<int,int>PII;typedefpair<string,int>PSI;constintN=1e5+5,INF=0x3f3f3f3f,Mod=1e6;constdoubleeps=1e-6;typedeflonglongll;i......
  • Codeforces 871 div4(重拳出击)
    Codeforces871div4ABC简单题D题意每次操作可以将当前的数分成两份,一份是\(\frac{1}{3}\),一份是\(\frac{2}{3}\),问当前数n可否进行若干次操作,最终出现一份大小为m的片。递归一下就好了,数据最大才\(10^7\)代码voiddfs(intx){ if(x==m){flag=1;return;} if(flag)re......
  • Codeforces Round 870 (Div. 2)
    CodeforcesRound870(Div.2)A-TrustNobody思路:枚举每一种说谎人数x,若a[i]大于x则说谎人数加一,判断最后说谎总人数是否为x,若是则输出x,结束枚举;若没有满足的x则-1#include<bits/stdc++.h>usingnamespacestd;typedefpair<int,int>PII;typedefpair<string,int>PSI;......
  • Codeforces Round 848 (Div. 2)C
    B.TheForbiddenPermutation一定要注意题目中说的是对于alli满足才算不好的,我们做的时候只要破坏一个i这个a就不算好的了,被这一点坑了,没注意到all。#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;constintN=2e5+10;intp[N],a[N];vo......