Codeforces Round #555 (Div. 3) A B C1(很水的题目)

A. Reachable Numbers

题意:设f(x)为 x+1 这个数去掉后缀0的数,现在给出n,问经过无数次这种变换后,最多能得到多少个不同的数。

代码

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>

const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int sum=0;
map<int,bool>mp;
int  f(int x)
{
    if(mp[x]==true)
    {
        return 1;
    }
    //cout<<sum<<endl;
    sum++;
    mp[x]=true;
    //cout<<x<<" "<<mp[x]<<endl;
    x++;
    while(x%10==0)
    {
        x/=10;
    }
    return f(x);
}
int main()
{
    int n;
    cin>>n;
    f(n);
    cout<<sum<<endl;
    return 0;
}

B. Long Number

题意:给一个长度为n的字符串,给出 f 数组表示你可以把字符 x 变成对应的 f (x),你只能修改一段连续的子串,求修改后字典序最大的字符串。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>

const int maxn=1e5+5;
typedef long long ll;
using namespace std;
map<char,char>mp;
int main()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    char c[2];
    for(int t=1;t<=9;t++)
    {
        char ss=‘0‘+t;
        cin>>c;
        mp[ss]=c[0];
    }
    int flag=0;
    for(int t=0;t<n;t++)
    {
        if(mp[str[t]]>str[t])
        {
            str[t]=mp[str[t]];
            flag=1;
        }
        else if(flag==1&&mp[str[t]]<str[t])
        {
            break;
        }
    }

    cout<<str<<endl;
    return 0;
}

C1. Increasing Subsequence (easy version)

题意:给一个长度为 n 的数组,每个数不一样,每次你可以从坐边界或者右边界取一个数,要求每一次取的数都要比上一次取得数要大,求最多可以取多少个数。

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>

const int maxn=1e5+5;
typedef long long ll;
using namespace std;
vector<int>vec;
int main()
{
    int n;
    cin>>n;
    int x;
    for(int t=0;t<n;t++)
    {
        scanf("%d",&x);
        vec.push_back(x);
    }
    vector<int>::iterator it1=vec.begin(),it2=vec.end()-1;
    vector<char>v;
    int xx=0;
    for(int t=0;t<n;t++)
    {
     if(*it2>xx||*it1>xx)
     {
         if(*it2<*it1&&*it2>xx&&*it1>xx)
         {
         xx=*it2;
         v.push_back(‘R‘);
         it2--;
        }
        else if(*it1<*it2&&*it2>xx&&*it1>xx)
        {
        xx=*it1;
         v.push_back(‘L‘);
         it1++;
        }
        else if(*it2>xx)
        {
         xx=*it2;
         v.push_back(‘R‘);
         it2--;
        }
        else if(*it1>xx)
        {
        xx=*it1;
         v.push_back(‘L‘);
         it1++;
        }
       // cout<<xx<<endl;
     }
    }
    cout<<v.size()<<endl;
    vector<char>::iterator it=v.begin();
    for(it=v.begin();it!=v.end();it++)
    {
        cout<<*it;
    }
    return 0;
}

原文地址:https://www.cnblogs.com/Staceyacm/p/10793279.html

时间: 2024-11-02 18:07:33

Codeforces Round #555 (Div. 3) A B C1(很水的题目)的相关文章

Codeforces Round #555 Div. 3

题目链接:戳我 完了,最菜就是我了.div.3都写不动QAQ A 按照题意模拟即可,注意判重 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #include<map> #define MAXN 100010 using namespace std; int

Codeforces Round #555 (Div. 3)[1157]题解

不得不说这场div3是真的出的好,算得上是从我开始打开始最有趣的一场div3.因为自己的号全都蓝了,然后就把不经常打比赛的dreagonm的号借来打这场,然后...比赛结束rank11(帮dreagonm上蓝果然没有食言qwq). (震惊...HA省A队CF青名...) CF1157A Reachable Numbers 水题,分析一下不难发现不超过\(10\)次就会少一位,然后\(10^9\)范围内的数可以到达的数个数显然不多,不妨大力模拟,然后把出现的数扔进set,最后输出set.size(

Codeforces Round # 555 (Div. 3) C2. Increasing subsequence (complicated version) (贪心)

题目链接:http://codeforces.com/contest/1157/problem/C2 当左右两边数字相同时,需要判断一下取哪边能得到更长的递增序列 #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <cstdio> #include <queue> #include <climits>

E Minimum Array ( Codeforces Round #555 (Div. 3) )

You are given two arrays aa and bb, both of length nn. All elements of both arrays are from 00 to n−1n−1. You can reorder elements of the array bb (if you want, you may leave the order of elements as it is). After that, let array cc be the array of l

Codeforces Round #337 (Div. 2) B. Vika and Squares 水题

B. Vika and Squares Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i. Vika also has an infinitely long rectangular piece of paper of width 1, consisting of s

Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题

B. Vasya and Wrestling Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, th

Codeforces Round #332 (Div. 2)A. Patrick and Shopping 水

A. Patrick and Shopping Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop an

Codeforces Round #298 (Div. 2) A. Exam(水)

题意:N 个学生 编了号,  然后第i个学生不能和第i+1和第i-1坐在一起,问合法的情况下最多坐多少个人,如何做 题解: 水题YY了一下,打表处理前三种    后面的情况就是在第三种情况下往前后插数字   奇数在后  偶数在前,然后没了 代码: #include<stdio.h> #include<string.h> int main() { int n, mymap[5005]; int mark[3][4] = {{1, 1}, {1, 1}, {2, 1, 3}}; whi

Codeforces Round #275 (Div. 1)A. Diverse Permutation (水)

题意: 从1-n的数,让你选择一些数来构造,要求每个相邻的数之间的绝对值之差有k种 题解: 先放好一个1   然后往后面插数字   先满足绝对值不同的  然后全插绝对值为1的, 代码: #include<stdio.h> #include<string.h> int main() { int n, k, a[100005], mark[100005]; while(scanf("%d %d", &n, &k) != EOF) { memset(a