Codeforces Round #643 (Div. 2)(A-E)題解

在這裏插入圖片描述
在這裏插入圖片描述
題目大意:
給你一個a1a1,要你求akak,其中ai=ai1+maxdigit(ai1)mindigit(ai1)ai=ai-1+maxdigit(ai-1) * mindigit(ai-1)maxgigit(123)=max(1,2.3)=3maxgigit(123)=max(1,2.3)=3
思路:
這題一開始我項會不會有循環節,因爲樣例a2a7maxdigit()mindigit()a2和a7的maxdigit()與mindigit()相同。然後寫了後面幾項發現並不是。不難發現如果出現00就可以直接不用算了,但是如果一直不出現00就很尷尬,但是沒不到其他思路了就按照找00寫了一發,就ACAC了,證明不太會。。。。
代碼:

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

typedef long long int ll;
const int maxn = 2e5 + 10;
void solved(){
	int t;cin>>t;
	while(t--){
		ll a1,k;cin>>a1>>k;
		set<int>st;
		ll temp = a1;
		int maxx = 0,minn = 10;
		while(a1 > 0){
			maxx = max(maxx,(int)(a1 % 10));
			minn = min(minn,(int)(a1 % 10));
			st.insert(a1 % 10);
			a1 /= 10;
		}
		ll tot = 1;
		while(tot < k && st.find(0)==st.end()){
			tot++;
			temp = temp + maxx * minn;
			ll t = temp;
			int minnn = 10,maxxx = 0;
			while(t > 0){
				maxxx = max(maxxx,(int)(t % 10));
				minnn = min(minnn,(int)(t % 10));
				st.insert(t % 10);
				t /= 10;
			}
			maxx = maxxx;minn = minnn;
		}
		cout<<temp<<endl;
	}
}
int main(){
	solved();
	return 0;
} 

在這裏插入圖片描述
在這裏插入圖片描述
題目大意:
給你一個長度爲nn的序列,aiai表示第ii個人的經驗值,現在你要對他們進行分組,當每組人數<=aiai<=ai,ai就可以加入這組,現在要你求最多能分多少組?
思路:
這個題好像很顯然,看題+寫代碼不到1010分鐘就aa了。就統計一下aiai的人數,然後ai/iai/i這樣分配肯定是最優的,aiai % ii可能不爲0,所以再用一個變量表示剩餘人數就行,剩餘人可以加到別的組。
代碼:

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

typedef long long int ll;
const int maxn = 2e5 + 10;
int cnt[maxn];
void solved(){
	int t;cin>>t;
	while(t--){
		int n;cin>>n;
		for(int i = 1; i <= n; i++)cnt[i] = 0;
		for(int i = 1; i <= n; i++){
			int a;cin>>a;cnt[a]++; 
		} 
		int ans = 0,rest = 0;
		for(int i = 1; i <= n; i++){
			ans += (cnt[i] + rest) / i;
			rest = (cnt[i] + rest) % i;
		}
		cout<<ans<<endl;
	}
}
int main(){
	solved();
	return 0;
} 

在這裏插入圖片描述
在這裏插入圖片描述
題目大意:
給你四個數:a,b,c,da,b,c,d,然後要你找三條邊a<=x<=b,b<=y<=c,c<=z<=da<=x<=b,b<=y<=c,c<=z<=d,滿足他們是一個非退化三角形,求非退化三角形的個數。
思路:
這個題也很簡單,非退化三角形指的是面積爲0不共線的三角形,通俗的講就是a+b!=ca+b!=c。先枚舉a+ba+b的個數,然後在[c,d][c,d]找有多少個數滿足x<a+bx<a+b就行了。統計個數要區間+1+1用個差分就行了。注意要開LL.
代碼:

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

typedef long long int ll;
const int maxn = 5e5 + 10;
ll cnt[maxn << 1 | 1];
void solved(){
	ll a,b,c,d;cin>>a>>b>>c>>d;
	for(ll i = a; i <= b; i++){
		cnt[i + b]++;cnt[i + c + 1]--;
	}
	for(ll i = 1; i <= maxn << 1; i ++)cnt[i] += cnt[i - 1];
	ll ans = 0;
	for(ll i = 1; i <= maxn << 1; i++){
		ans += cnt[i] * max(0LL,(min(d,i - 1) - c + 1));
	}
	cout<<ans<<endl;
}
int main(){
	solved();
	return 0;
} 

在這裏插入圖片描述
在這裏插入圖片描述
題目大意:
要你構造一個長度爲nn的序列使得他們的和爲ss。現在你指定一個數kk,問選擇一段連續的區間的和能不能得到kk,如果能,輸出“NO”,非則輸出"YES",並且輸出你構造的數組以及kk
思路:
構造一個[1,1,1,1,...,sn1][1,1,1,1,...,s-n-1]數組選k=nk=n
代碼:

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

const int maxn = 1e6 + 10;
int cnt[maxn];
void solved(){
	int n,s;cin>>n>>s;
	int l1 = 1,r1 = n - 1;
	int l2 = s - (n - 1),r2 = s;
	for(int i = l1 ; i <= r1; i++)cnt[i]=1;
	for(int i = l2 ; i <= r2; i++)cnt[i]=1;
	int ans = -1;
	for(int i = 1; i <= n; i++){
		if(cnt[i] == 0){
			ans = i;break;
		}
	}
	if(ans != -1){
		cout<<"YES"<<endl;
		for(int i = 1; i <= n - 1; i++){
			cout<<"1"<<" ";
		}
		cout<<s - (n - 1)<<endl;
		cout<<ans<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}
int main(){
	solved();
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章