前言
传送门 :
(B>D>C>A) 新人友好场 (EFQAQ)
A.
题意 :
Alice和Bob用a[]和b[]玩打牌,一人出一个最后不能出的算输,打牌的规则显然是越大越牛,询问两人分别先手的胜负情况
思路 :
这题显然不需要怎么动脑,上来就是一个王炸即可
言简意赅也就是,谁手上有最大的谁就赢,同时有先手赢(思路是显然的不给证明)
这题写慢了,直接sort或者∗max{}会快个几秒钟
code :
int a[N];
int b[N];
int n,m;
void solve(){
cin>>n;
int maxna = 0;
int maxnb = 0 ;
for(int i = 1;i<=n;i++){
cin>>a[i];
maxna = max(maxna,a[i]);
}
cin>>m;
for(int i=1;i<=m;i++){
cin>>b[i];
maxnb = max(maxnb,b[i]);
}
if(maxna == maxnb){
cout<<"Alice"<<endl;
cout<<"Bob"<<endl;
return;
}
if(maxna > maxnb){
cout<<"Alice"<<endl;
cout<<"Alice"<<endl;
return;
}
cout<<"Bob"<<endl;
cout<<"Bob"<<endl;
}
B.
题意 :
给定一个数组a[],和一个询问数组b[],对于每个b[i]是将前a[b[i]]个数放到数组后面,问操作之后首位是多少
思路 :
首先这里的思路其实从A题进行了延申
因为最后答案是求首位是多少,我们贪心的从大局进行考虑,我们发现其实只需要每次交换指向当前首位的指针即可,因为最终都是首位的指针在变
所以我们按操作进行模拟即可
code :
int n,m;
int a[N],b[N];
void solve(){
cin>>n;
for(int i = 0 ;i< n; i ++ )cin>>a[i];
cin>>m;
int u = 0;
for(int i = 0 ;i<m; i++ ){
cin>>b[i];
u = (u+b[i])%n;
}
cout<<a[u]<<endl;
}
C.
题意 :
给定a[],b[]询问在有限的操作内是否可以完成排序。
操作定义如下 :
选中i.j交换swap(a[i],a[j]),swap(b[i],b[j])
思路 :
这题要么就是我做过类似的题,要么就是太简单了
我们可以将a[]看成多个组,然后对a[]进行排序,这样子相同的数会在一起
而相同的a[]就构成了一个组
然后我们在对每个组里面的数进行排序即对b[]进行排序
最后判断一下 b[] 是否有序即可
code :
int a[N],b[N];
void solve(){
vector<pii> ans;
cin>>n;
mp.clear();
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
for(int i=1;i<=n;i++){
for(int j = 1; j < i ;j ++ ){
if(a[i] < a[j]){
swap(a[i],a[j]);
swap(b[i],b[j]);
ans.pb({i,j});
}
}
}
// for(int i=1;i<=n;i++)
// cout<<a[i]<<" ";
// cout<<endl;
//
//
for(int i=1;i<=n;){
int j = n;
while(a[j]!=a[i]) j --;
if(j == i){
i = j+1;
}
for(int k = i ;k <= j ;k ++){
for(int t = i ; t < k ; t ++ ){
if(b[k] < b[t]){
swap(b[k],b[t]);
ans.pb({k,t});
}
}
}
i = j+1;
}
// for(int i=1;i<=n; i++ )
// cout<<b[i]<<" ";
// cout<<endl;
//
for(int i = 2;i<=n;i++){
if(b[i] < b[i-1]){
cout<<"-1"<<endl;
return;
}
}
cout<<ans.size()<<endl;
for(auto t : ans){
cout<<t.x<<" "<<t.y<<endl;
}
}
int main(){
int t;cin>>t;while(t--)
solve();
return 0 ;
}
D.
题意 :
给定n,x,询问是最小次数的操作使得x的位数为n
操作定义如下 :
我们可以选中x上的每一位0−9然后令其x=x∗t
如下反复操作
思路 :
因为最小,同时还因为是位数
所以范围在19并且是最小,所以考虑bfs
n≤19则说明在longlong范围内,因为1e18正好19位,因此可以在ll范围内进行bfs
就是很简单的bfs 中间特判一下0,1即可
然后就是开ll的问题,因为不想开全局ll搞得我调了半小时
最后需要特判1以及特判10,10这种位数上只有1,0的情况
code :
// Problem: D. Required Length
// Contest: Codeforces - Educational Codeforces Round 129 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1681/problem/D
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <algorithm>
using namespace std;
#define IOS ios::sync_with_stdio(false);
#define CIT cin.tie(0);
#define COT cout.tie(0);
#define int long long
#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--)
#define cer(a) cerr<<#a<<'='<<(a)<<" @ line "<<__LINE__<<" "<<endl
typedef priority_queue<int,vector<int>,greater<int>> Pri_m;
typedef pair<int,int> pii;
typedef vector<int> VI;
map<ll,int> mp;
const int N = 2e5+10,INF = 0x3f3f3f3f;
const double eps = 1e-5;
int n,x;
int get(ll u){
int ws = 0 ;
while(u!=0){
ws++;
u/=10;
}
return ws;
}
struct node{
ll val,step;
};
int bfs(){
queue<node> q;
q.push({x,1});
mp[x] = 1;
while(!q.empty()){
auto t = q.front();
q.pop();
vector<int> v;
ll temp = t.val;
while(temp!=0){
v.pb(temp%10);
temp/=10;
}
for(auto u : v){
if(u == 1 || !u) continue;
// cout<<u<<" " << t.val<<endl;
ll tt = u*t.val;
ll ws = get(tt);
if(mp[tt]) continue;
mp[tt] = 1;
if(ws > n)break;
if(ws == n){
//cout<<tt<<" "<<ws<<" "<<x<<endl;
return t.step;
}
q.push({tt,t.step+1});
}
}
}
void solve(){
cin>>n>>x;
if(x == 1){
if(n == 1) cout<<0<<endl;
else cout<<-1<<endl;
return;
}
int flag = 0 ;
int t = x;
while(t){
int r = t%10;
if(r!=0 && r!=1){
flag = 1;
break;
}
t/=10;
}
if(!flag){
cout<<-1<<endl;
return;
}
cout<<bfs()<<endl;
}
signed main(){
//int t;cin>>t;while(t--)
solve();
return 0 ;
}
B题确实难住我啦哈哈哈