首页 > 其他分享 >Pinely Round 3 (Div. 1 + Div. 2)

Pinely Round 3 (Div. 1 + Div. 2)

时间:2023-12-28 11:47:59浏览次数:43  
标签:int Pinely void namespace long Div include Round

A. Distinct Buttons

image
image

#include<bits/stdc++.h>
using namespace std;
void solve(){
	int n;
	cin>>n;
	int a=0,b=0,c=0,d=0;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		if(x>0)a=1;
		if(y>0)b=1;
		if(x<0)c=1;
		if(y<0)d=1;
	}
	if(a&&b&&c&&d){
		cout<<"NO\n";
	}else{
		cout<<"YES\n";
	}
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

B. Make Almost Equal With Mod

image
image

首先会想到2,因为除以2不是0就是1,但是碰到全是奇或全是偶就不好使了,那么就将2扩大一倍,image

#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[200];
void solve(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int m=1;
	while(1){
		int k=(long long)1<<m;
		set<int>ans;
		for(int i=1;i<=n;i++){
			ans.insert(a[i]%k);
		}
		if(ans.size()==2){
			cout<<k<<"\n";
			return;
		}
		m++;
	}
}
signed main(){
    ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	int t;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

C. Heavy Intervals

image
image

首先如果区间都是不相交的,是换不了的,所以只能去改变相交的,假使两个区间相加,想要权值最小化,是不是就应该让更多的区间去乘小的值,更少的区间去乘大的值,所以可以转换区间。

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
int l[N],r[N],c[N],p[N];
void solve(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>l[i];
	for(int i=1;i<=n;i++)cin>>r[i];
	for(int i=1;i<=n;i++)cin>>c[i];
	set<int>s(l+1,l+1+n);
	sort(r+1,r+1+n);
	for(int i=1;i<=n;i++){
		auto it=s.lower_bound(r[i]);
		l[i]=*prev(it);
		p[i]=r[i]-l[i];
		s.erase(prev(it));
	}
	sort(p+1,p+1+n,greater<int>());
    sort(c+1,c+1+n);
    int ans=0;
    for(int i=1;i<=n;i++){
    	ans+=(p[i]*c[i]);
	}
	cout<<ans<<"\n";
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

标签:int,Pinely,void,namespace,long,Div,include,Round
From: https://www.cnblogs.com/yufan1102/p/17932359.html

相关文章

  • 题解 P9993【[Ynoi Easy Round 2024] TEST_133】
    就硬把线段树3和数列分块入门2揉到一起出。维护原数组\(a\)及其历史最大值\(hist\),对每个块,维护块内\(a\)升序排序后结果\(p\)、块内\(a\)升序排序后历史最大值前缀和\(prehist\)、块加标记\(add\)、块历史和加标记\(histadd\)。下传标记和区间修改操作仿照线......
  • 记一次el-checkbox包裹一层div,点击div勾选复选框,点击复选框却没反应的bug
    <divclass="account-item"v-for="iteminaccountList":key="item.id":class="[{'is-select-mode':isSelectMode},{'is-select':item.isSelect}]"@click="selectItem......
  • codeforces刷题(1100):1904B_div2
    B、CollectingGame跳转原题点击此:该题地址1、题目大意  获得一个由n位正整数组成的数组。你可以选择选择任意一个数作为你的判断值。然后任意一个\(\le\)它的数可以被选中加入你的分数(注意判断值不算在里面),同时该数被移除数组。你的任务是,对于该数组中的每个数,都将其作为......
  • LibreOJ#535. 「LibreOJ Round #6」花火
    LibreOJ#535.「LibreOJRound#6」花火\(n\)个烟火排成一排,从左到右高度分别为\(h_1,h_2,\cdots,h_n\),这些高度两两不同。每次Yoko可以选择两个相邻的烟火交换,这样的交换可以进行任意多次。每次Yoko还可以选择两个不相邻的烟火交换,但这样的交换至多进行一次。你的任务......
  • codeforces刷题(1100):1905B_div2
    B、Begginer'sZelda跳转原题点击此:此题地址1、题目大意  给你一个子树,你可任意选择两个节点\(u、v\),这两个节点之间的所有节点(包括\(u、v\))都将结合变为一个新的节点。要求你通过该操作将所有的节点变为只有一个节点,求最小的操作数。2、题目解析  由题意可得:当\(u、v\)......
  • Codeforces Round 915 (div2) E
    E.TreeQueries[题目链接](https://codeforces.com/contest/1904/problem/EProblem-E-Codeforces)题意概括:给定一棵大小为\(n\)的树,回答如下询问,询问之间相互独立:给定一个点\(x\)与\(k\)个点\(a_i\),求出从\(x\)出发不经过任何一个\(a_i\)的最长简单路径长度......
  • codeforces刷题(1100):1917B_div2
    模板B、EraseFirstorSecondLetter跳转原题点击此:该题地址1、题目大意  给你一个字符串,可以执行任意次以下操作,生成最终的字符串(不可为空),问你能生成的不重复字符串数为多少。操作一:删除字符串第一个字符;操作二:删除字符串第二个字符。2、题目解析  发现,操作一:即选......
  • div4 题目
    .Dashboard-CodeforcesRound898(Div.4)-Codeforces1.Problem-G-Codeforces这一题我们首先进行分类讨论,因为情况很多第一种情况当首尾存在一个B的情况时,我们可以吃掉所有的A,这个时候只需要计算出A的数量就可以第二种情况是当首尾都是A,但是中间有连续的B的时候,这个......
  • 让div盒子居中
    <template><!--<divclass="about"><h1>Thisisanonepage</h1></div>--><divclass="about"><!--1.给盒子设置宽高,然后用margin:0auto;--><divclass="one">第一种......
  • P5840 [COCI2015] Divljak
    题意:Alice有\(n\)个字符串\({S}_1,{S}_2,\ldots,{S}_n\),Bob有一个字符串集合\({T}\),一开始集合是空的。接下来会发生\(q\)个操作,操作有两种形式:1P:Bob往自己的集合里添加了一个字符串\({P}\)。2x:Alice询问Bob,集合\({T}\)中有多少个字符串包含串\({S}_x\)(......