C-小红关鸡_牛客周赛 Round 35 (nowcoder.com)
//超时 134.17/175 主要是循环这部分的问题
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 6;
const int inf = 0x3f3f3f3f;
int a[N];
void solve()
{int n,k;cin>>n>>k;for(int i=0;i<n;i++)cin>>a[i];sort(a,a+n);int max1=0,cn=1;for(int i=0;i<n;i++){for(int j=i+1;j<n;j++){if(a[j]-a[i]<=k){cn++;}else break;}max1=max(cn,max1);cn=1;}cout<<max1*1.0/n;
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);int t = 1;//cin>>t;while (t--) {solve();}return 0;
}//ac代码:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 6;
const int inf = 0x3f3f3f3f;
int a[N];
void solve()
{int n,k;cin>>n>>k;for(int i=0;i<n;i++)cin>>a[i];sort(a,a+n);int max1=0,cn=1;for(int i=0,j=0;i<n;i++){while(a[i]-a[j]>k)j++;max1=max(max1,i-j+1);}cout<<max1*1.0/n;
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);int t = 1;//cin>>t;while (t--) {solve();}return 0;
}
D-小红的排列构造_牛客周赛 Round 35 (nowcoder.com)
//0/175,,,就是老把简单的问题搞那么复杂,,到最后找错也好麻烦,,注意这点
/*
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 6;
const int inf = 0x3f3f3f3f;
int a[N],b[N],c[N];
struct node{int x,xx;
}no[N];
set<int>se;
void solve()
{int n,cn=0,h=0;cin>>n;for(int i=0;i<n;i++){cin>>a[i];c[i]=a[i];b[i]=i+1;se.insert(a[i]);}sort(a,a+n);for(int i=0;i<n;i++){if(a[i]>n)b[++h]=a[i];else{if(a[i]==a[i-1])b[++h]=a[i];}}for(int i=0;i<n;i++){for(int j=1;j<=h;j++){if(c[i]==b[j]){b[j]=i+1;break;c[i]=0;}}}//for(int i=1;i<=h;i++)cout<<b[i]<<endl;//return ;int k=0,s=1;for(int i=1;i<=n;i++){if(se.find(i)!=se.end())continue;else{cn++;no[++k].x=i;no[k].xx=b[s];s++;}}cout<<cn<<endl;for(int i=1;i<=cn;i++){cout<<no[i].xx<<' '<<no[i].x<<endl;}
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);int t = 1;//cin>>t;while (t--) {solve();}return 0;
}
*/ac代码:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 6;
const int inf = 0x3f3f3f3f;
int a[N],b[N];
void solve()
{int n,x,cn=0;memset(a,0,sizeof a);cin>>n;for(int i=1;i<=n;i++){cin>>x;if(x<=n&&a[x]==0)a[x]=1;else{cn++;b[cn]=i;}}cout<<cn<<endl;for(int i=1;i<=n;i++){if(a[i]==0){cout<<b[cn]<<' '<<i<<endl;cn--;}}
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);int t = 1;//cin>>t;while (t--) {solve();}return 0;
}
F-小红的子序列权值和(easy)_牛客周赛 Round 35 (nowcoder.com)
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
map<int,int>mp;
int a[5];
int find(int x)
{int result=1;for(int i=0;i<x;i++){result*=2;result%=mod;}return result;
}
void solve()
{int n,x,sum=0;cin>>n;for(int i=0;i<n;i++){cin>>x;a[x]++;}int ans=find(a[1]);ans%=mod;ans*=(find(a[2])%mod+(a[2]*find(a[2]-1)%mod)%mod);ans%=mod;ans*=(find(a[3])%mod+(a[3]*find(a[3]-1)%mod)%mod);ans%=mod;cout<<ans-1;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);int t=1;//cin>>t;while(t--){solve();}return 0;
}