zoukankan      html  css  js  c++  java
  • Codeforces Round #529 (Div. 3) 练习赛

    image-20200904205312641

    Examples

    input

    6
    baabbb
    

    output

    bab
    

    input

    10
    ooopppssss
    

    output

    oops
    

    思路:

    模拟等差数列即可

    #include<bits/stdc++.h>
    using namespace std;
    int main() {
    	//freopen("in.txt", "r", stdin);
    	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    	int n; string s, ss = "";
    	cin >> n >> s; int t = 1;
    	for (int i = 0; i < n; i += t) {
    		ss += s[i], ++t;
    	}
    	cout << ss << endl;
    }
    

    Examples

    input

    4
    1 3 3 7
    

    output

    2
    

    input

    2
    1 100000
    

    output

    0
    

    Note

    In the first example you can remove (7) then instability of the remaining array will be (3−1=2).

    In the second example you can remove either 11 or 100000100000 then instability of the remaining array will be $100000−100000=0 $ and (1−1=0) correspondingly.

    思路:

    取删最小值或最大值的min

    #include<bits/stdc++.h>
    using namespace std;
    int a[100100];
    int main() {
    	//freopen("in.txt", "r", stdin);
    	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    	int n; cin >> n;
    	for (int i = 1; i <= n; ++i)cin >> a[i];
    	sort(a + 1, a + 1 + n);
    	cout << min(a[n - 1] - a[1], a[n] - a[2]) << endl;
    }
    

    image-20200904205614259

    Examples

    input

    9 4
    

    output

    YES
    1 2 2 4 
    

    思路:

    #include<bits/stdc++.h>
    using namespace std;
    multiset<int>s;
    int main() {
    	//freopen("in.txt", "r", stdin);
    	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    	int n, k;
    	cin >> n >> k;
    	int m = n;
    	for (int i = 0; m; m >>= 1, ++i)if (m & 1)s.insert(1 << i);
    	if (n < k || s.size() > k) cout << "NO" << endl;
    	else {
    		while (s.size() < k) {
    			int a = *(--s.end()); s.erase(--s.end());
    			if (a == 1)break;
    			s.insert(a / 2);
    			s.insert(a / 2);
    		}
    		cout << "YES" << endl;
    		while (s.size()) {
    			cout << *s.begin() << " ";
    			s.erase(s.begin());
    		}
    	}
    }
    

    • 思路: 随便选定一个起点即可。那就选择 1吧 , 选择建边 来把原来的图 恢复, 题目给出的信息是这个点后面的两个点
    • 我们不能确定这个点与谁相连,当能知道的是 后面的两个点一定相连,所以建两个无向边,最终得到的vector 是 每个点都有
    • 两个相连的点,一左一右, 题目让输出的是 从左往右 ,所以我们要保证 dfs恢复图的过程中 从1出发是往后走 。
    • 第一个遍历的是 g[ 1 ] [ 0 ]所以保证 g[ 1 ] [ 0 ]是 1后面的点即可。

    Ps:成功复习了一遍DFS.

    #include<bits/stdc++.h>
    using namespace std;
    #define maxn 234567
    vector<int>g[maxn],o;
    int n,x,y,s,t;
    void dfs(int u,int p)
    {
        if(o.size()==n)return ;
        o.push_back(u);
        if(o.size()==n)return ;
        for(int i=0; i<2; i++)
        {
            if(g[u][i]==p)continue;
            dfs(g[u][i],u);
        }
    }
    int main()
    {
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d",&x,&y);
            if(i==1)s=x,t=y;
            g[x].push_back(y);
            g[y].push_back(x);
        }
        if(g[1][1]==s||g[1][1]==t)swap(g[1][0],g[1][1]);
        dfs(1,0);
        for(int i=0; i<n-1; i++)printf("%d ",o[i]);
        printf("%d
    ",o[n-1]);
        return 0;
    }
    

    The desire of his soul is the prophecy of his fate
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    Javascript笔记09:Javascript的下拉式导航菜单
    Javascript笔记08:Javascript的if...else语句
    Android(java)学习笔记84:SQLiteDatabase的query方法参数
    Android(java)学习笔记83:各种边距设置
    Android(java)学习笔记82:利用SpannableString设置复合文本
    PHP笔记06:http响应中的状态码
    html笔记04:在html之中导入css两种常见方法
    POJ 3307 Smart Sister
    ZOJ 2872 Binary Partitions
    HDU 4685 Prince and Princess
  • 原文地址:https://www.cnblogs.com/RioTian/p/13616169.html
Copyright © 2011-2022 走看看