Codeforces Round #387 (Div. 2)

自闭了,还是谷歌搜索好用。

看到两年半之前的铜牌学妹打了这场就vp了一波果然被捶爆了www。

啊系学妹!我死啦!

A:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int main(){
 5     ios::sync_with_stdio(false);
 6     int n;cin>>n;
 7     int a,b;
 8     for(int i=1;i*i<=n;i++){
 9         if(n%i==0){
10             a=i,b=n/i;
11         }
12     }
13     cout<<a<<' '<<b<<endl;
14 }
View Code

B:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int n;string s;
 5 int a[5],c[5];
 6 map<int,char> mp;
 7 int main(){
 8     ios::sync_with_stdio(false);
 9     cin>>n;if(n%4)cout<<"===",exit(0);
10     cin>>s;
11     mp[0]='A',mp[1]='G',mp[2]='C';mp[3]='T';
12     for(int i=0;i<n;i++){
13         if(s[i]=='A')a[0]++;
14         else if(s[i]=='G')a[1]++;
15         else if(s[i]=='C')a[2]++;
16         else if(s[i]=='T')a[3]++;
17         else a[4]++;
18     }
19     int mx = max(max(a[0],a[1]),max(a[2],a[3]));
20     int ned = 4*mx-a[0]-a[1]-a[2]-a[3];
21     if(a[4]<ned)cout<<"===",exit(0);
22     for(int i=0;i<5;i++)
23         c[i]=mx-a[i],c[i]+=(a[4]-ned)/4;
24     for(int i=0;i<n;i++){
25         if(s[i]=='?'){
26             for(int j=0;j<4;j++){
27                 if(c[j]>0){
28                     c[j]--;
29                     s[i]=mp[j];
30                     break;
31                 }
32             }
33         }
34     }
35     cout<<s<<endl;
36 }
View Code

C:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int N = 1e5+5;
 5 int n,q;
 6 int tim[105];
 7 int t,k,d;
 8 int main(){
 9     ios::sync_with_stdio(false);
10     cin>>n>>q;
11     while (q--){
12         cin>>t>>k>>d;
13         int cnt = 0;
14         for(int i=1;i<=n;i++){
15             if(tim[i]<=t)cnt++;
16         }
17         if(cnt<k){
18             cout<<-1<<endl;
19             continue;
20         }
21         int sum = 0;
22         for(int i=1;i<=n;i++){
23             if(tim[i]<=t){
24                 k--;
25                 tim[i]=t+d;
26                 sum+=i;
27             }
28             if(!k)break;
29         }
30         cout<<sum<<endl;
31     }
32 }
View Code

D:显然贪心。贪完了check一下最后一段行不行(如果有的话)

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int N=2e5+5;
 5 int n,k;
 6 int t[N];
 7 priority_queue<int,vector<int>,greater<int>> q;
 8 int main(){
 9     ios::sync_with_stdio(false);
10     //q.push(1);q.push(3);cout<<q.top();
11     cin>>n>>k;
12     int cnt = 0,ans = 0;
13     for(int i=1;i<=n;i++)cin>>t[i];
14     t[n+1]=-1;t[0]=1;
15 
16     for(int i=1;i<=n;i++){
17         if(t[i]<0)
18             cnt++;
19         if(t[i]*t[i-1]<0||(t[i]==0&&t[i-1]<0)||(t[i]<0&&t[i-1]==0))
20             ans++;
21     }
22     if(cnt>k)cout<<-1,exit(0);
23     swap(cnt,k);
24     cnt-=k;
25     for(int l=1,r;l<=n;){
26         if(t[l]>=0) {
27             l++;
28             continue;
29         }
30         r=l+1;
31         while (r<=n&&t[r]>=0)r++;
32         if(r-l-1>0&&r<=n) {
33             q.push(r - l - 1);
34         }
35         l=r;
36     }
37     while (!q.empty()&&cnt>0){
38         int x = q.top();
39         q.pop();
40         if(x>cnt)break;
41         cnt-=x;
42         ans-=2;
43     }
44     if(cnt>0){
45         int id = -1;
46         if(t[n]>=0) {
47             for (int i = n; i >= 1; i--) {
48                 if (t[i] < 0) {
49                     id = i;
50                     break;
51                 }
52             }
53             if (id != -1) {
54                 if (cnt >= n - id) {
55                     ans--;
56                 }
57             }
58         }
59     }
60     cout<<ans<<endl;
61 }
View Code

E:就搜一下就没了吧。。。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int N = 1E6+6;
 5 string s;
 6 int fa[N];
 7 vector<string> v,ans[N],a;
 8 vector<int> c;
 9 int dep[N],b[N];//dfs建树划分森林
10 int cnt = 0;
11 void dfs(int x){
12     b[x]=1;
13     cnt++;
14     if(x>=c.size())return;
15     for(int i=0;i<c[x];i++){//他有这些儿子
16         fa[cnt]=x;
17         dep[cnt]=dep[x]+1;
18         dfs(cnt);
19     }
20 }
21 int main(){
22     ios::sync_with_stdio(false);
23     cin>>s;
24     string tmp = "";
25     for(int i=0;i<s.length();i++){
26         if(s[i]==','){
27             v.push_back(tmp);
28             tmp = "";
29         } else
30             tmp+=s[i];
31     }
32     v.push_back(tmp);
33     int n = v.size();
34     for(int i = 0;i<n;i++){
35         if(i%2==0){//字符串
36             a.push_back(v[i]);
37         } else{
38             int num = 0;
39             for(int j=0;j<v[i].size();j++){
40                 num = num*10+(v[i][j]-'0');
41             }
42             c.push_back(num);
43         }
44     }
45     n = a.size();
46     for(int i=0;i<n;i++){
47         if(b[i]==0) {//祖先
48             dfs(i);
49         }
50     }
51     int mx = 0;
52     for(int i=0;i<n;i++){
53         mx = max(dep[i],mx);
54         ans[dep[i]].push_back(a[i]);
55         //cout<<a[i]<<endl;
56     }
57     cout<<1+mx<<endl;
58     for(int i=0;i<=mx;i++){
59         for(auto tmp:ans[i]){
60             cout<<tmp<<' ';
61         }
62         cout<<endl;
63     }
64 }
View Code

F:搜了好久,,到最后谷歌了一下找到了好多。

抄的别人的。感觉自己现在写不出来。下面是链接

https://www.cnblogs.com/Saurus/p/6208757.html

我们用dp[i][j]表示用前i个数字填了j个位置的方案数。那么其实就是一个背包。。。被治了一天。。

那么如果不用 数字 i 的 话,dp[i][j]=sigma(dp[i-1][j-k]*C[len-j+k][k]);  (0<=k<=min(j,cnt[i]))

这样子我们就能得到 长度为len时的方案数了。

然后先算一下总长度,然后从高位向低位开始枚举,特判一下前导0.

 1 #include <bits/stdc++.h>
 2 typedef long long ll;
 3 using namespace std;
 4 const int N = 31;
 5 ll C[N][N],dp[16][N];//前i个数字占j个位置
 6 int cnt[16];
 7 ll k;int t;
 8 void init(){
 9     for(int i=0;i<N;i++){
10         C[i][0]=1;
11         for(int j=1;j<=i;j++){
12             C[i][j]=C[i-1][j]+C[i-1][j-1];
13         }
14     }
15 }
16 ll slove(int len){
17     memset(dp,0, sizeof(dp));
18     for(int i=0;i<=cnt[0];i++)dp[0][i]=C[len][i];
19     for(int i=1;i<16;i++){
20         for(int j=0;j<=len;j++){
21             for(int k=0;k<=min(j,cnt[i]);k++){
22                 dp[i][j]+=dp[i-1][j-k]*C[len-(j-k)][k];//我们有k个空位qwq
23             }
24         }
25     }
26     return dp[15][len];
27 }
28 void pt(int j){
29     if(j < 10) cout<<j;
30     else cout<<(char)(j+'a'-10);
31 }
32 int main(){
33     ios::sync_with_stdio(false);
34     init();
35     cin>>k>>t;
36     for(int i=0;i<16;i++)cnt[i]=t;
37     int len = 1;
38     for(;;len++){
39         ll tmp=0;
40         if(len==1)tmp=15;
41         else{
42             for(int i=1;i<16;i++){
43                 cnt[i]--;
44                 tmp+=slove(len-1);
45                 cnt[i]++;
46             }
47         }
48         if(k>tmp)k-=tmp;
49         else break;
50     }
51     for(int i=len;i>0;i--){
52         if(i==1){
53             for(int j=0;j<16;j++){
54                 if(j==0&&len==1)continue;
55                 if(cnt[j]>0)k--,cnt[j]--;
56                 if(k==0){pt(j);exit(0);}
57             }
58         } else{
59             for(int j=0;j<16;j++){
60                 if(i==len&&j==0)continue;
61                 cnt[j]--;
62                 ll tmp = slove(i-1);
63                 if(k>tmp)k-=tmp;
64                 else{
65                     pt(j);
66                     break;
67                 }
68                 cnt[j]++;
69             }
70         }
71     }
72 }
View Code

 

posted @ 2019-03-19 19:20  MXang  阅读(130)  评论(0编辑  收藏  举报