0
点赞
收藏
分享

微信扫一扫

[cf] Educational Codeforces Round 123 (Rated for Div. 2)

7dcac6528821 2022-04-14 阅读 47
c++

前言

传送门 :

A.

我们可以使用 t o l o w e r tolower tolower进行小写化然后使用 m a p map map进行处理

Code

void solve(){
	int n;cin>>n;
	for(int i = 0 ; i< n;i ++ ){
		string s;cin>>s;
		mp.clear();
		
		int flag = 0 ;
		
		for(auto x : s){
			if(x>= 'A'&& x<='Z'){
				if(mp[tolower(x)]) mp[tolower(x)] -- ;
				else{
					cout<<"NO"<<endl;
					flag = 1;
					
					break;
				}
			}else mp[tolower(x)] = 1;
		}
		if(!flag) cout<<"YES"<<endl;
		
		
	}
	
}

B.

没有写出来

CODE

// Problem: B. Anti-Fibonacci Permutation
// Contest: Codeforces - Educational Codeforces Round 123 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1644/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
#define IOS  ios::sync_with_stdio(false);
#define CIT  cin.tie(0);
#define COT  cout.tie(0);

#define ll long long
#define x first
#define y second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),x.end()
#define Fup(i,a,b) for(int i=a;i<=b;i++)
#define Fde(i,a,b) for(int i=a;i>=b;i--)

typedef priority_queue<int,vector<int>,greater<int>>  Pri_m;
typedef pair<int,int> pii;
typedef vector<int> VI;
map<int,int> mp;
const int N = 60;
int p[N];
int n;
int st[N];

// bool check(int p[]){
	// for(int i=3;i<=n;i++){
		// if(p[i] == p[i-1]+p[i-2]) return false;
	// }
	// return true;
// }
// void solve(){
	// cin>>n;
	// for(int i=1;i<=n;i++) p[i] = i;
// 	
	// int idx =0  ;
// 	
	// do{
		// if(check(p)){
			// ++idx;
			// if(idx == n+1) return;
			// for(int i=1;i<=n;i++)
			// cout<<p[i]<<" ";
			// cout<<endl;
		// }
	// }while(next_permutation(p+1,p+1+n));
// }

int idx;

void dfs(int u){

	if(idx == n+1) return;

	if(u>=3){
		if(p[u] == p[u-1] + p[u-2]) return;
	}
	
	if(u == n+1){
		
		for(int i=3;i<=n;i++){
			if(p[i] == p[i-1] + p[i-2])return ;
		}
		++idx;
		if(idx == n+1) return;
	
		for(int i = 1; i <= n;i++){
			cout<<p[i]<<' ';
		}
		cout<<endl;
		return;
	}
	
	for(int i = 1; i<=n;i++){
		if(!st[i]){
			p[u] = i;
			st[i] = 1;
			dfs(u+1);
			st[i] = 0 ;
		}
	}
}
void solve(){
	idx = 0 ;
	cin>>n;
	dfs(1);
	memset(st,0,sizeof st);
}
int main(){
	IOS
	CIT
	COT
    int t;cin>>t;while(t--)
    solve();
    return 0 ;
}

举报

相关推荐

0 条评论