首页 > 其他分享 >SMU Summer 2024 Contest Round 2 (7.9)zhaosang

SMU Summer 2024 Contest Round 2 (7.9)zhaosang

时间:2024-07-14 19:53:15浏览次数:17  
标签:Summer Contest int SMU new using size ll carpet

A-A

http://162.14.124.219/contest/1006/problem/A

考查用vector画图
我枚举到n==5才开始用,浪费40分钟,还是找规律太慢,得多学
做题代码如下:一坨

#include <bits/stdc++.h>

using namespace std;

using ll =long long;
const ll N =1e6+8;
char v[1000001];
int w[10000001];

ll diff[N],prefix[N];
vector<vector<char>> generate_carpet(int N) {
	if (N == 0) {
		return {{'#'}};
	}
	
	vector<vector<char>> smaller_carpet = generate_carpet(N - 1);
	int size = smaller_carpet.size();
	int new_size = size * 3;
	vector<vector<char>> new_carpet(new_size, vector<char>(new_size, '.'));
	
	for (int i = 0; i < new_size; ++i) {
		for (int j = 0; j < new_size; ++j) {
			if (!(size <= i && i < 2 * size && size <= j && j < 2 * size)) {
				new_carpet[i][j] = smaller_carpet[i % size][j % size];
			}
		}
	}
	
	return new_carpet;
}

void print_carpet(const vector<vector<char>>& carpet) {
	for (const auto& row : carpet) {
		for (char ch : row) {
			cout << ch;
		}
		cout << endl;
	}
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	ll n;
	cin>>n;
	if(n==1){
		cout<<"###"<<'\n';
		cout<<"#.#"<<'\n';
		cout<<"###"<<'\n';
	}else if(n==2){
		cout<<"#########"<<'\n';
		cout<<"#.##.##.#"<<'\n';
		cout<<"#########"<<'\n';
		cout<<"###...###"<<'\n';
		cout<<"#.#...#.#"<<'\n';
		cout<<"###...###"<<'\n';
		cout<<"#########"<<'\n';
		cout<<"#.##.##.#"<<'\n';
		cout<<"#########"<<'\n';
	}else if(n==0){
		cout<<"#"<<'\n';
		}else if(n==3)
		{
cout<<"###########################"<<'\n';			
cout<<"	#.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"###########################"<<'\n';
cout<<"###...######...######...###"<<'\n';
cout<<"#.#...#.##.#...#.##.#...#.#"<<'\n';
cout<<"###...######...######...###"<<'\n';
cout<<"###########################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"###########################"<<'\n';
cout<<"#########.........#########"<<'\n';
cout<<"#.##.##.#.........#.##.##.#"<<'\n';
cout<<"#########.........#########"<<'\n';
cout<<"###...###.........###...###"<<'\n';
cout<<"#.#...#.#.........#.#...#.#"<<'\n';
cout<<"###...###.........###...###"<<'\n';
cout<<"#########.........#########"<<'\n';
cout<<"#.##.##.#.........#.##.##.#"<<'\n';
cout<<"#########.........#########"<<'\n';
cout<<"###########################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"###########################"<<'\n';
cout<<"###...######...######...###"<<'\n';
cout<<"#.#...#.##.#...#.##.#...#.#"<<'\n';
cout<<"###...######...######...###"<<'\n';
cout<<"###########################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"###########################"<<'\n';
		
			}else if(n==4){
cout<<"#################################################################################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"###...######...######...######...######...######...######...######...######...###"<<'\n';
cout<<"#.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.#"<<'\n';
cout<<"###...######...######...######...######...######...######...######...######...###"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"#########.........##################.........##################.........#########"<<'\n';
cout<<"#.##.##.#.........#.##.##.##.##.##.#.........#.##.##.##.##.##.#.........#.##.##.#"<<'\n';
cout<<"#########.........##################.........##################.........#########"<<'\n';
cout<<"###...###.........###...######...###.........###...######...###.........###...###"<<'\n';
cout<<"#.#...#.#.........#.#...#.##.#...#.#.........#.#...#.##.#...#.#.........#.#...#.#"<<'\n';
cout<<"###...###.........###...######...###.........###...######...###.........###...###"<<'\n';
cout<<"#########.........##################.........##################.........#########"<<'\n';
cout<<"#.##.##.#.........#.##.##.##.##.##.#.........#.##.##.##.##.##.#.........#.##.##.#"<<'\n';
cout<<"#########.........##################.........##################.........#########"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"###...######...######...######...######...######...######...######...######...###"<<'\n';
cout<<"#.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.#"<<'\n';
cout<<"###...######...######...######...######...######...######...######...######...###"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"###########################...........................###########################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.#...........................#.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"###########################...........................###########################"<<'\n';
cout<<"###...######...######...###...........................###...######...######...###"<<'\n';
cout<<"#.#...#.##.#...#.##.#...#.#...........................#.#...#.##.#...#.##.#...#.#"<<'\n';
cout<<"###...######...######...###...........................###...######...######...###"<<'\n';
cout<<"###########################...........................###########################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.#...........................#.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"###########################...........................###########################"<<'\n';
cout<<"#########.........#########...........................#########.........#########"<<'\n';
cout<<"#.##.##.#.........#.##.##.#...........................#.##.##.#.........#.##.##.#"<<'\n';
cout<<"#########.........#########...........................#########.........#########"<<'\n';
cout<<"###...###.........###...###...........................###...###.........###...###"<<'\n';
cout<<"#.#...#.#.........#.#...#.#...........................#.#...#.#.........#.#...#.#"<<'\n';
cout<<"###...###.........###...###...........................###...###.........###...###"<<'\n';
cout<<"#########.........#########...........................#########.........#########"<<'\n';
cout<<"#.##.##.#.........#.##.##.#...........................#.##.##.#.........#.##.##.#"<<'\n';
cout<<"#########.........#########...........................#########.........#########"<<'\n';
cout<<"###########################...........................###########################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.#...........................#.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"###########################...........................###########################"<<'\n';
cout<<"###...######...######...###...........................###...######...######...###"<<'\n';
cout<<"#.#...#.##.#...#.##.#...#.#...........................#.#...#.##.#...#.##.#...#.#"<<'\n';
cout<<"###...######...######...###...........................###...######...######...###"<<'\n';
cout<<"###########################...........................###########################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.#...........................#.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"###########################...........................###########################"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"###...######...######...######...######...######...######...######...######...###"<<'\n';
cout<<"#.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.#"<<'\n';
cout<<"###...######...######...######...######...######...######...######...######...###"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"#########.........##################.........##################.........#########"<<'\n';
cout<<"#.##.##.#.........#.##.##.##.##.##.#.........#.##.##.##.##.##.#.........#.##.##.#"<<'\n';
cout<<"#########.........##################.........##################.........#########"<<'\n';
cout<<"###...###.........###...######...###.........###...######...###.........###...###"<<'\n';
cout<<"#.#...#.#.........#.#...#.##.#...#.#.........#.#...#.##.#...#.#.........#.#...#.#"<<'\n';
cout<<"###...###.........###...######...###.........###...######...###.........###...###"<<'\n';
cout<<"#########.........##################.........##################.........#########"<<'\n';
cout<<"#.##.##.#.........#.##.##.##.##.##.#.........#.##.##.##.##.##.#.........#.##.##.#"<<'\n';
cout<<"#########.........##################.........##################.........#########"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"###...######...######...######...######...######...######...######...######...###"<<'\n';
cout<<"#.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.##.#...#.#"<<'\n';
cout<<"###...######...######...######...######...######...######...######...######...###"<<'\n';
cout<<"#################################################################################"<<'\n';
cout<<"#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.#"<<'\n';
cout<<"#################################################################################"<<'\n';
			
			}else{
			vector<vector<char>> carpet = generate_carpet(n);
				print_carpet(carpet);
				
				}

}

B-B

http://162.14.124.219/contest/1006/problem/B

就是问你字符串里面有多少个连续相同的两个的子串数量,
但是问的是某一个区间里面的。
思路就是先找出所有的子串,然后再开一个数组,保存子串的数量在位置上
然后利用一个前缀和就可以找到答案了

#include <bits/stdc++.h>

using namespace std;

using ll =long long;
const ll N =1e6+8;
char v[1000001];
int w[10000001];

ll diff[N],prefix[N];
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	ll n,q;
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>v[i];
		}
	for(int i=1;i<=n;i++){
		if((v[i]==v[i+1])){
			w[i]=1;
		}
	}
	for(int j=1;j<=n;j++) prefix[j]=prefix[j-1]+w[j];
	while(q--){
		ll l,r;
		cin>>l>>r;
		if(w[r]==1){
			cout<<prefix[r]-prefix[l-1]-1<<'\n';
		}else{
			cout<<prefix[r]-prefix[l-1]<<'\n';
		}
		
	}
		
}
C-C 最近在训练二分,可惜前面时间浪费太多,现在看到很高兴,会做了。 思路==就是二分加模拟,判断条件是最多行数>=使用的数量,这样模拟,把每一个数 加在一个数中,如果这个数小于二分的答案继续加下一个,直到大于等于,然后行数加1 (就是每一行要满足二分的答案),最后如果行数超了限制说明大了,如果可以继续二分继续变大== 代码如下:
#include <bits/stdc++.h>
using namespace std;

using ll =long long;

const ll inf = 2e18;

vector<ll>v(10000001);

ll m,n;
bool check(ll x){
	vector<ll>pd(1);
	for(int i=1;i<=n;i++){
		if(v[i]>x) return false;
		if(pd.back()==0){
			pd.back()+=v[i];
		}else{
			if(pd.back()+v[i]+1ll<=x){
				pd.back()+=1ll+v[i];
			}else
				pd.push_back(v[i]);
		}
	}
	return pd.size()<=m;
}



int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>v[i];
	ll l=1,r=inf;
	ll ans=-1;
	while(l<=r){
		ll mid =(l+r)>>1;
		if(check(mid)) ans=mid,r=mid-1;
		else l=mid+1;
		
	}
	cout<<ans;
	return 0;	
	
}

标签:Summer,Contest,int,SMU,new,using,size,ll,carpet
From: https://www.cnblogs.com/dontian/p/18301910

相关文章

  • SMU Summer 2024 Contest Round 3(7.10)zhaosang
    打的最菜一次,最惨一次,题读假了A-Ahttp://162.14.124.219/contest/1007/problem/A签到题要解决这道题,素数对,数据量不是很大,所以我们可以先预处理素数,这个偶数肯定是等于小于它的两个素数,所以只需要遍历到小于它即可,把素数存起来,然后这两个素数的和等于这个偶数,并且要求相差最小......
  • 2023 Henan Provincial Collegiate Programming Contest
    和零时加的队友打了一下,计算几何摆了,最优化摆了,adhoc摆了。A.小水獭游河南枚举前缀,是\(O(|\Sigma|)\)的,然后判断一下是不是回文串即可。B.ArtforRest昨天才做过这个套路的加强版。显然只用判断类似\(\max(a,b)<\min(b+1,c)\)的条件。暴力枚举是调和级数的。C.Toxel......
  • Toyota Programming Contest 2024#7(AtCoder Beginner Contest 362)
    这场比赛还是比较水的A,B,C跳过D题dij把点权和边权都转换为边权即可E题DP可以用\(map\)存一下等差数列的差先说\(O(n^4)\),\(f_{len,i,j,t}\)分别表示长度,现在在\(i\),上一个在\(j\)显然动态转移方程就有了\(f_{len,i,j,k}=\sum_{k=1}^{k=j-1}f_{len-1,j,k,t}\)点击查看......
  • AtCoder Beginner Contest 362 补题记录(A~E,G)
    A分三类情况讨论即可。voidsolveqwq(){intr=io.read(),g=io.read(),b=io.read();stringqwq=io.readstring();if(qwq=="Blue")printf("%lld\n",min(r,g));elseif(qwq=="Red")printf("%lld\n",......
  • 南京大学计算理论之美 (Summer 2024)暑期学校游记
    day-nzero4338和我说有这么个暑校,报名了day0到了钟山风雨地,石头城下水南京到了南京大学(仙林校区),被硬件震撼了一波和zero4338两人互相贩卖焦虑:为啥还没预习这个,也没预习那个到了南京大学(鼓楼校区),和同学转鼓楼校区,和同学和zero4338和同学吃饭回酒店之后说预习预习,但是......
  • SMU Summer 2024 Contest Round 3
    1.To3原题链接:http://162.14.124.219/contest/1007/problem/I记录数组中除3余数的种类和个数,以及数组元素总和除3的余数,最后判断(考虑总余数为1,两个元素余数为2和总余数为2,两个元素余数为1的特殊情况)查看代码#include<bits/stdc++.h>#defineintlonglongusingnamespa......
  • SMU Summer 2024 Contest Round 2
    1.MinimumWidth原题链接:http://162.14.124.219/contest/1006/problem/C二分一行最大容量,如果check小于等于总行数就扩大,反之则缩小查看代码#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;intn,m;inta[1000000],b[1000000];boolcheck(intx){......
  • SMU Summer 2024 Contest Round 3(7.10)
    寻找素数对思路:数的范围为10000,直接筛出所有范围内的质数,n2的枚举所有质数对和的情况#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong#definePIIpair<int,int>constintN=1e4+5;vector<int>pri;intidx,st[N];voidinit(){for(in......
  • SMU Summer 2024 Contest Round 3
    SMUSummer2024ContestRound3寻找素数对题意给你一个偶数,找到两个最接近的素数,其和等于该偶数。思路处理出1e5以内的素数,然后遍历,更新最接近的答案。代码#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong;vector<int>euler_range(intn){......
  • SMU Summer 2024 Contest Round 2
    Sierpinskicarpet1.这道题的核心其实在于,我们要观察到点的位置是在每一个小图形的正方形内,和一个大图型的中心正方形处的,那么通过观察可以发现,如果满足在这个正方形处,那么一定(3k-1+1)<=x,y<=(2*3k-1)2.这个k是什么意思呢?当我们n=3的时候k可以取1,2,3,也就是对应每一级的中间宫......