首页 > 其他分享 >The 2020 ICPC Asia Shenyang Regional Programming Contest Northeastern University(SMU 2024 ICPC 网络赛选拔

The 2020 ICPC Asia Shenyang Regional Programming Contest Northeastern University(SMU 2024 ICPC 网络赛选拔

时间:2024-10-07 16:11:33浏览次数:6  
标签:typedef Contest int ll Regional long ICPC ++ define

The 2020 ICPC Asia Shenyang Regional Programming Contest Northeastern University(SMU 2024 ICPC 网络赛选拔赛2)

D. Journey to Un'Goro

思路

队友写得,没看。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define PII pair<int,int>
#define endl '\n'
typedef long long ll;
const int N = 2e5;
vector<bitset<100000>>q;
map<int, int>hm;
vector<string>a;
int b[N];
void solve() {
	int n;
	cin >> n;
	if (n <= 20) {
		int mx = 0;
		for (int i = 0; i < (1 << n); i++) {
			int t = i;
			string s = "";
			int tt = 0;
			for (int j = 0; j < n; j++) {
				if (t & 1)s += 'r';
				else s += 'b';
				tt *= 2;
				tt += t & 1;
				t /= 2;
			}
			int mm = 0;
			for (int j = 0; j < n; j++) {
				b[j + 1] = b[j] + (s[j] == 'r');
			}
			for (int j = 0; j < n; j++) {
				for (int k = j; k < n; k++) {
					int ss = b[k + 1] - b[j];
					if (ss & 1) {
						mm++;
					}
				}
			}
			if (mm > mx) {
				a.clear();
				q.clear();
				mx = mm;
				a.push_back(s);
			} else if (mm == mx) {
				a.push_back(s);
			}
		}
		cout << mx << endl;
		sort(a.begin(), a.end());
		for (int i = 0; i < a.size() && i < 100; i++) {
			cout << a[i] << endl;
//		cout<<i<<endl;
		}
	}else{
		int mx=0;
		if(n&1){
			mx=((n+1)/2)*((n+1)/2);
		}else{
			mx=((n+1)/2)*((n+1)/2+1);
		}
		bitset<100000>s=1;
		int p=((n+1)/2)-1;
		q.push_back((s<<p));
		s<<=p;
		if((n&1)==0)q.push_back(s<<1);
		s<<=1;
		p++;
		for(int i=0;i<p;i++){
			if(q.size()>=100)break;
			if(i==0){
				s[i]=1;
			}else if(i==1){
				s[i]=1;
			}else{
				s[i]=1;
				s[i-2]=0;
			}
			q.push_back(s);
		}
		s=1;
		p++;
		s<<=p;
		for(int i=0;i<(1<<p);i++){
			if(q.size()>=100)break;
			int mm=0;
			for (int j = 0; j < n; j++) {
				b[j + 1] = b[j] + (s[j] == 1);
			}
			for (int j = 0; j < n; j++) {
				for (int k = j; k < n; k++) {
					int ss = b[k + 1] - b[j];
					if (ss & 1) {
						mm++;
					}
				}
			}
			if(mm==mx)q.push_back(s);
			int f=1,pos=0;
			while(f){
				if(s[pos]==1){
					f=1;
					s[pos]=0;
				}else{
					s[pos]=1;
					f=0;
				}
				pos++;
			}
		}
		s=1;
		p++;
		s<<=p;
		for(int i=0;i<(1<<p);i++){
			if(q.size()>=100)break;
			int mm=0;
			for (int j = 0; j < n; j++) {
				b[j + 1] = b[j] + (s[j] == 1);
			}
			for (int j = 0; j < n; j++) {
				for (int k = j; k < n; k++) {
					int ss = b[k + 1] - b[j];
					if (ss & 1) {
						mm++;
					}
				}
			}
			if(mm==mx)q.push_back(s);
			int f=1,pos=0;
			while(f){
				if(s[pos]==1){
					f=1;
					s[pos]=0;
				}else{
					s[pos]=1;
					f=0;
				}
				pos++;
			}
		}
		cout<<mx<<endl;
		for (int i = 0; i < q.size() && i < 100; i++) {
			for(int j=n-1;j>=0;j--){
				if(q[i][j]==1){
					cout<<'r';
				}else{
					cout<<'b';
				}
			}
			cout<<endl;
		}
	}

}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}

	return 0;
}

F. Kobolds and Catacombs

思路

将 \(a\) 排序后的数组设为 \(b\),然后判断 \(a\) 和 \(b\) 中非递减序列在 \(a\) 中覆盖的区间,尽可能的分小即可。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define PII pair<int,int>
#define endl '\n'
typedef long long ll;
vector<int>q;
map<int, int>hm;

void solve() {
	int n;
	cin >> n;
	vector<int>a(n);
	vector<int>st1(n), st2(n);
	vector<int>b(n);
	for (int i = 0; i < n ; ++i) {
		cin >> a[i];
		b[i] = a[i];
	}
	int ans = 0;
	sort(b.begin(), b.end());
	q = b;
	q.erase(unique(q.begin(), q.end()), q.end());
	for (int i = 0; i < q.size(); i++) {
		hm[q[i]] = i;
	}
	int s = 0;
	for (int i = 0; i < n ; ++i) {
		int p = hm[a[i]];
		st1[p]++;
		if (st1[p] > st2[p]) {
			s++;
		} else {
			s--;
		}
		p = hm[b[i]];
		st2[p]++;
		if (st1[p] < st2[p]) {
			s++;
		} else {
			s--;
		}
		if (s == 0) {
			ans++;
		} else {

		}
	}
	cout << ans << endl;

}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}

	return 0;
}

G. The Witchwood

思路

倒序排序后取前 \(k\) 个的和即可。

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define PII pair<int,int>
#define endl '\n'
typedef long long ll;

void solve() {
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for (int i = 0; i <n ; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(),greater<int>());
    int ans=0;
    for (int i = 0; i <k ; ++i) {
        ans+=a[i];
    }
    cout<<ans<<endl;

}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}

I. Rise of Shadows

思路

队友写的,大致就是运用数论的同余关系。

网上看到一篇不错的题解,贴一下 2020 icpc 沈阳 I - Rise of Shadows(思维) - limil - 博客园 (cnblogs.com)

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define LL __int128
#define PII pair<int,int>
#define endl '\n'
typedef long long ll;
const int N = 2e5;
vector<bitset<100000>>q;
map<int, int>hm;
vector<string>a;
int b[N];
void solve() {
	int h,m,A;
	cin >> h>>m>>A;
    
	if(A*2+1>=h*m){
		cout<<h*m<<endl;
		return;
	}
	int gg=__gcd(h-1,h*m);
	LL s1=((h-1)/gg);
	LL s2=((h*m)/gg);
	int ans=0;
	ans+=(h*m)/s2*(A/gg*2+1);
	cout<<ans<<endl;

}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}

	return 0;
}

K.Scholomance Academy

思路

英文一大堆,其实就是让你找到临界点,然后求图中这样每个临界点构成的矩形的面积并。

好像队友写得有点复杂(?,不过A了就行,%%%。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define double long double
#define LL __int128
#define PII pair<double,double>
#define PIC pair<int,char>
#define endl '\n'
typedef long long ll;
const int N = 1e6+10;
vector<PIC>q;
int b[N];
vector<PII>ans;
map<double,double>hm;
void solve() {
	int n;
	cin>>n;
	double s1=0,s2=0;
	for(int i=1;i<=n;i++){
		char x;
		int y;
		cin>>x>>y;
		q.push_back({y,x});
		if(x=='+')s1+=1;
		if(x=='-')s2+=1;
	}
	sort(q.begin(),q.end());
	int s=0;
	double s3=0,s4=0;
	for(int i=0;i<q.size();i++){
		char x=q[i].second;
		if(s==q[i].first){
			if(x=='+')s3+=1;
			if(x=='-')s4+=1;
			continue;
		}
		hm[(s2-s4)/s2]=max(hm[(s2-s4)/s2],(s1-s3)/s1);
		if(x=='+')s3+=1;
		if(x=='-')s4+=1;
		s=q[i].first;
	}
//	cout<<s1<<s2<<s3<<s4<<endl;
	hm[(s2-s4)/s2]=max(hm[(s2-s4)/s2],(s1-s3)/s1);
	for(auto[u,v]:hm){
		ans.push_back({u,v});
	}
	sort(ans.begin(),ans.end());
	ans.push_back({1,1});
	double sum=0;
	for(int i=0;i<ans.size()-1;i++){
		sum+=ans[i].second*(ans[i+1].first-ans[i].first);
	}
	cout<<fixed<<setprecision(10)<<sum<<endl;
	

}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}

	return 0;
}

标签:typedef,Contest,int,ll,Regional,long,ICPC,++,define
From: https://www.cnblogs.com/Kescholar/p/18450201

相关文章

  • AtCoder Beginner Contest 374
    ABC374A-Takahashisan2题目传送门代码(签到题)#include<cstdio>#include<cctype>#include<cstring>#include<cmath>#include<queue>usingnamespacestd;intiut(){ intans=0,f=1;charc=getchar(); while(!isdigit(c))f=(c==&......
  • The 10th Shandong Provincial Collegiate Programming Contest
    A-Sekiro题意初始有\(n\)个金币,死了\(m\)次,死一次\(n=\lceil\fracn2\rceil\)。求最后的金币数。思路模拟。代码点击查看代码#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve(){ intn,m; cin>>n>>m; while(m--......
  • ICPC2023沈阳K
    https://codeforces.com/gym/104869/problem/KDS题尽量进一步思考,简化维护过程权值线段树上二分首先得出一个显然的转化:对于每次操作,求出此次下所有正数从小到大的前缀和的第一次大于所有负数和的绝对值的位置即为答案。赛时做法既然要求每次都求a升序下的前缀和,很显然的想......
  • AtCoder Beginner Contest 374
    省流版A.判断末三位即可B.逐位判断即可C.枚举所有分组情况即可D.枚举线段顺序、端点顺序即可E.二分答案,发现贵的机器数量不超过\(100\),枚举求最小花费看是否可行即可F.朴素DP,复杂度分析得到有效时刻不超过\(O(n^2)\)而非\(O(s_i)\),直接\(DP\)即可A-Takahashi......
  • 2017中国大学生程序设计竞赛 - 女生专场(SDKD 2024 Summer Training Contest K2)
    A-AutomaticJudge题意\(n\)个问题,\(m\)条记录,每条记录有题号、时间、状态,第一次\(AC\)的时候计入罚时,其他没发罚\(20\)分钟。求队伍过题数和罚时。思路模拟。代码点击查看代码#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve()......
  • The 2024 CCPC Shandong Invitational Contest and Provincial Collegiate Programmin
    比赛链接C.ColorfulSegments2考虑最小的分组数量,可以先按左端点排序,然后每次贪心地找到前面一个最大右端点\(r_j<l_i\)的组加入。考虑计数,还是同样地按左端点排序,那么假设现在有\(k\)个组,每个组最大右端点是\(g_i\)(没有元素则\(g_i=0\)),那么每次可以选择一个\(g_j......
  • 2023ICPC 沈阳
    赛时5题xixike仍然是平衡树大神。gxd仍然是计数大神。而我签了三个到下班。c题签到,略J:结论题E:bfs的一个dp,第一次写写了比较久K:xixike平衡树过的。赛后补题的时候我先是写了一个双log动态开点权值线段树,然后别人教我线段树二分到了单log。但是直接离散化不动态开点的......
  • The 2024 CCPC Shandong Invitational Contest and Provincial Collegiate Programmin
    Preface传说中被杭电1h十题的比赛,结果打到结束也只会10题这场开局就不太顺,一个Easy题C卡到2h的时候才出,虽然中期题基本都能想到但还是出的很慢最后1h讨论了下L的大致做法发现了几个关键性质后觉得写不完了,遂摆烂滚去打炉石了A.Printer签到,二分答案大力检验即......
  • The 2021 ICPC Asia Shenyang Regional Contest
    B-BitwiseExclusive-ORSequence题意\(n\)个数,\(m\)个关系,每个关系形如\(a_u⊕a_v=w\),表示第\(u\)个数与第\(v\)数的异或运算结果为\(w\)。求是否有这样的\(n\)个数满足所有关系要求,如果没有输出\(-1\),如果有输出所有满足要求的方案中,所有数字的和的最小值。思路建图......
  • Skills - 2022 International Collegiate Programming Contest, Jinan Site, Problem
    有3种技能,\(n(\le10^3)\)天内每天可以对一个技能进行学习,第i天学习第j个技能可以为第j个技能增加\(a_{i,j}(\le10^4)\)的熟练度。在第i天结束时,每个技能的熟练度会减去距离上次学习该技能的天数,但最多减到0。求n天后能得到的熟练度的和的最大值。首先容易有一个显然的dp状态:\(f......