Codeforces Round #479 (Div. 3)

从今天开始记录每一场cf。

历史性的第一场div3的比赛。

ac数量:4

rating变化:-5

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <math.h>
#include <queue>
#include <vector>
#include <climits>
using namespace std;
const int  Max_M= 1e3 + 10;
const int inf = 0x01010101;
int main()
{
    // freopen("out.txt","w",stdout);
    ios::sync_with_stdio(false);
    int n,k;
    cin.tie(0);
    cin>>n>>k;
    while(k--)
    {
        if(n%10)
            n--;
        else n/=10;
    }
    cout<<n<<endl;
    return 0;
}
//A


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <math.h>
#include <queue>
#include <vector>
#include <climits>
using namespace std;
const int  Max_M= 1e3 + 10;
const int inf = 0x01010101;
int Count(string s,string pat)
{
    int pos = 0,cnt = 0;
    while(pos != -1)
    {
        pos = s.find(pat,pos+1);
        if(pos != -1)break;
        cnt++;
    }
    return cnt;
}
int main()
{
    // freopen("out.txt","w",stdout);
    ios::sync_with_stdio(false);
    string s;
    int n,mmax = -1;
    cin.tie(0);
    cin>>n>>s;
    string ans ;
    for(int i = 0; i < n - 1; i++)
    {
        int tmp = Count(s,s.substr(i,2));
        if( tmp > mmax)
        {
            mmax = tmp;
            ans = s.substr(i,2);
        }
    }
    cout<<ans<<endl;
    return 0;
}
//B

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <math.h>
#include <queue>
#include <vector>
#include <climits>
using namespace std;
const int  Max_M= 2e5 + 10;
const int inf = 0x01010101;
int a[Max_M];
int main()
{
    // freopen("out.txt","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin>>n>>k;
    for(int i = 0; i < n; i++)
        cin>>a[i];
    sort(a,a+n);
    if(k == 0)
    {
        if(a[0] == 1)
            cout<<"-1"<<endl;
        else cout<<"1"<<endl;
        return 0;
    }
    if(n == 1 || n == k)
    {
        cout<<a[k-1]<<endl;
        return 0;
    }
    if(a[k-1] == a[k])
        cout<<"-1"<<endl;
    else cout<<a[k-1]<<endl;
    return 0;
}

//C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <math.h>
#include <queue>
#include <vector>
#include <climits>
using namespace std;
typedef long long ll;
const int  Max_M= 2e3 + 10;
const int inf = 0x01010101;
ll a[Max_M];
vector<ll> ans;
int flag;
bool used[Max_M];
int n;
void dfs(int index)
{
    if(flag) return ;
    if(index == n)
    {
        cout<<ans[0];
        flag = 1;
        for(int i = 1; i < ans.size(); i++)
            cout<<" "<<ans[i];
        cout<<endl;
        return ;
    }
    for(int i = 0 ; i < n; i++)
    {
        if(used[i] == 1)continue;
        if(index == 0)
        {
            for(int j = 0; j < n; j++)
            {
                used[j] = 1;
                ans.push_back(a[j]);
                dfs(index + 1);
                ans.pop_back();
                used[j] = 0;
            }
        }
        if(a[i] * 3 == ans[ans.size()-1] || a[i] == ans[ans.size()-1] * 2)
        {
            used[i] = 1;
            ans.push_back(a[i]);
            dfs(index + 1);
        }
        ans.pop_back();
        used[i] = 0;

    }

}
int main()
{
    // freopen("out.txt","w",stdout);
    cin>>n;
    for(int i = 0; i < n; i++)
        scanf("%lld",&a[i]);
    dfs(0);
    return 0;
}

//D


#include <bits/stdc++.h>
using namespace std;
const int MAX_V = 2e5 + 10;
vector<int> G[MAX_V];
int n, m, flag;
bool visit[MAX_V];
void dfs(int index)
{
	visit[index] = 1;
	if (G[index].size() != 2)
		flag = 0;
	for (auto i : G[index])
		if (!visit[i])
			dfs(i);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	int a, b;
	while (m--)
	{
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		flag = 1;
		if (!visit[i]) //如果还没被访问过
		{
			dfs(i);
			if (flag) ans++;
		}
	}
	cout << ans << endl;
}//E


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <math.h>
#include <queue>
#include <vector>
#include <climits>
#include <map>
using namespace std;
typedef long long ll;
const int  Max_M= 2e5 + 10;
const int inf = 0x01010101;
map<int,int> T;
int a[Max_M];
int main()
{
    // freopen("out.txt","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int mmax = 0, k;
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
        T[a[i]] = T[a[i] - 1] + 1;
        if(T[a[i]] > mmax)
        {
            mmax = T[a[i]];
            k = a[i];
        }
    }
    cout<<mmax<<endl;
    int start = k - mmax + 1;
    for(int i = 0; i < n && start <= k; i++)
    {
        if(a[i] == start)
        {
            cout<<i+1<<' ';
            start++;
        }
    }
    return 0;
}
//F


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值