2022-2023-1ACM集訓(xùn)隊(duì)每周程序設(shè)計(jì)競(jìng)賽(12)題解-創(chuàng)新互聯(lián)

問(wèn)題 A: 富哥買水果

創(chuàng)新互聯(lián)為企業(yè)級(jí)客戶提高一站式互聯(lián)網(wǎng)+設(shè)計(jì)服務(wù),主要包括成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、成都app開發(fā)、小程序開發(fā)、宣傳片制作、LOGO設(shè)計(jì)等,幫助客戶快速提升營(yíng)銷能力和企業(yè)形象,創(chuàng)新互聯(lián)各部門都有經(jīng)驗(yàn)豐富的經(jīng)驗(yàn),可以確保每一個(gè)作品的質(zhì)量和創(chuàng)作周期,同時(shí)每年都有很多新員工加入,為我們帶來(lái)大量新的創(chuàng)意。 

思路:輸出yi等于0對(duì)應(yīng)的下標(biāo)i即可。

#include//#include//#include//#include#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<,greater>q;
#define INF 0x3f3f3f3f
#define endl '\n'
//functiondfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=998244353;
int n;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	vectora(5,0);
	int res=0;
	for(int i=0;i<5;i++){
		cin>>a[i];
		if(a[i]==0)res=i+1;
	}
	cout<

問(wèn)題 B: 富哥買寵物

思路:顯然y是偶數(shù)且大于等于2*x小于等于4*x時(shí)有解。

#include//#include//#include//#include#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<,greater>q;
#define INF 0x3f3f3f3f
#define endl '\n'
#define eps 1e-6
//functiondfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=998244353;
int n;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	int x,y;
	cin>>x>>y;
	if(y>=2*x&&y<=4*x&&y%2==0){
		cout<<"Yes";
	}
	else cout<<"No";
}

問(wèn)題 C: 禁止出現(xiàn)

思路:由于N和pi都小于100,所以直接從小到大枚舉Y到X的距離,然后判斷Y是否在p內(nèi)就行。

#include//#include//#include//#include#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<,greater>q;
#define INF 0x3f3f3f3f
#define endl '\n'
#define eps 1e-6
//functiondfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=998244353;
int n;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	int x;
	cin>>x>>n;
	sett;
	for(int i=0;i>tt;t.insert(tt);
	}
	for(int i=0;i<=100;i++){
		if(!t.count(x-i)){
			cout<

問(wèn)題 D: 不能整除

思路:對(duì)于每個(gè)ai直接枚舉所有因子判斷是否在數(shù)組a內(nèi)即可(對(duì)于ai要特殊判斷ai這個(gè)因子)。

#include//#include//#include//#include#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<,greater>q;
#define INF 0x3f3f3f3f
#define endl '\n'
//functiondfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=998244353;
int n;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	cin>>n;
	vectora(n);
	vectorcnt(1000001,0);
	for(int i=0;i>a[i];
		cnt[a[i]]++;
	}
	int res=0;
	for(int i=0;i0)f=0;
				else if(j==a[i]&&cnt[j]>1)f=0;
				if(a[i]/j!=a[i]&&cnt[a[i]/j]>0)f=0;
				else if(a[i]/j==a[i]&&cnt[a[i]/j]>1)f=0;
			}
		}
		if(f)res++;
	}
	cout<

問(wèn)題 E: 幼兒園老大

思路:對(duì)于每個(gè)班級(jí)用一個(gè)multiset去維護(hù)其中的可愛(ài)程度大的值是多少,然后將每個(gè)班級(jí)可愛(ài)程度大的值再放進(jìn)存儲(chǔ)答案的multiset中,去維護(hù)其中的最小值。接下來(lái)根據(jù)題意去模擬過(guò)程即可。

#include//#include//#include//#include#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<,greater>q;
#define INF 0x3f3f3f3f
#define endl '\n'
//functiondfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=998244353,N=2e5+10;
int n,q;
multisett[N];
multisetres;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	cin>>n>>q;
	vectora(n+1);
	vectorb(n+1);
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		t[b[i]].insert(a[i]);
	}
	for(int i=1;i<=200000;i++){
		if(t[i].size()){
			auto j=t[i].rbegin();
			res.insert(*j);
		}
	}
	while(q--){
		int c,d;
		cin>>c>>d;
		res.erase(res.find(*t[b[c]].rbegin()));
		if(t[d].size())res.erase(res.find(*t[d].rbegin()));
		t[b[c]].erase(t[b[c]].find(a[c]));
		if(t[b[c]].size())res.insert(*t[b[c]].rbegin());
		t[d].insert(a[c]);
		res.insert(*t[d].rbegin());
		b[c]=d;
		cout<<*res.begin()<

問(wèn)題 F: 付哥愛(ài)游泳

思路: 我們可以想到這是一個(gè)邊權(quán)都為1的圖求單源最短路,所以我們可以用Dijkstra算法,但由于邊數(shù)可能很多所以我們要考慮如何去優(yōu)化,對(duì)于一個(gè)點(diǎn) i 來(lái)說(shuō)如果經(jīng)過(guò)他走到 j 所花費(fèi)的代價(jià)比目前走到 j 的代價(jià)-1還要大的話,那么從 i 接著往下走顯然是不優(yōu)于從 j 開始往下走的所以這時(shí)候應(yīng)該break,停止從 i 繼續(xù)往后走的操作,這樣從 i 走出的邊數(shù)將大大減小,就可以得到答案了。

#include//#include//#include//#include#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<,greater>q;
#define INF 0x3f3f3f3f
#define endl '\n'
//functiondfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=998244353,N=1e6+10;
const int d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int n,m,k;
int x_1,x_2;
int y_1,y_2;
string a[N];
int dis[N];
bool f[N];
int id(int x,int y){
	return (x-1)*m+y;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	cin>>n>>m>>k;
	cin>>x_1>>y_1>>x_2>>y_2;
	for(int i=1;i<=n*m;i++)dis[i]=1e9;
	priority_queue,greater>q;
	for(int i=1;i<=n;i++){
		string t;
		cin>>t;
		a[i]=" "+t;
	}
	q.push({0,id(x_1,y_1)});
	dis[id(x_1,y_1)]=0;
	while(q.size()){
		auto t=q.top();
		q.pop();
		if(f[t.second])continue;
		f[t.second]=1;
		int x=t.second/m+1;
		int y=t.second%m;
		if(y==0){
			x--;
			y=m;
		}
		int last=id(x,y);
		for(int i=0;i<4;i++){
			int tx=x,ty=y;
			for(int j=1;j<=k;j++){
				tx+=d[i][0];
				ty+=d[i][1];
				int tem=id(tx,ty);
				if(tx<1||tx>n||ty<1||ty>m||a[tx][ty]=='@'||dis[tem]dis[id(x,y)]+1) {
					dis[tem]=dis[id(x,y)]+1;
					q.push({dis[tem],tem});
				}
			}
		}
	}
	if(dis[id(x_2,y_2)]==1e9){
		cout<<"-1";
	}
	else {
		cout<

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧

分享題目:2022-2023-1ACM集訓(xùn)隊(duì)每周程序設(shè)計(jì)競(jìng)賽(12)題解-創(chuàng)新互聯(lián)
瀏覽路徑:http://bm7419.com/article16/igdgg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站微信公眾號(hào)、建站公司、ChatGPT網(wǎng)站制作做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)