2020.10.02 Rating 补题报告

A - Remove a Progression

题意:给出一个长度,构造一个1,2,3……,n 的数列,第i步去掉第i个奇数,之后剩下的数构成一个新数列,问最后第x个数是多少

做法:好家伙一开始写了一大串子,结果啥用都没有,在纸上打表看看,结果不正好就是2*x吗……

代码:

//去吧马里奥!把AC公主救回来!
//        ********
//       ************
//       ####....#.
//     #..###.....##....
//     ###.......######
//        ...........
//       ##*#######
//    ####*******######
//   ...#***.****.*###....
//   ....**********##.....
//   ....****    *****....
//     ####        ####
//   ######        ######
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<map>
#include<sstream>
#include<cstring>
#include<vector>
#include<iomanip>
#include<queue>
#include<set>
#define LL long long
#define _64 __int64
const double PI = atan(1.)*4.;
using namespace std;

//int a[100000005];

int main(){
    int t;
    cin >> t;
    while(t--){
        int n,x;
        cin >> n >> x;

       /* int m = 1;
        for(int i = 1; i <= n;i++){
            a[i] = i;
        }
        int count = 0;
        for(int i = 1;i <= n;i++){
            if(a[i] % 2 == 1){
                a[i] = -1;
                count++;
            }

            if((n - count) < i){
                break;
            }
        }
        //for(int i = 1;i <= n;i++){
         //   cout << a[i] << endl;
        //}
        int num = 0;
        for(int i= 1;i <= n;i++){
            if(a[i] == -1){

                continue;
            }else{
                num++;
                if(num == x){
                cout << a[i] << endl;
                break;
                }else{
                    continue;
                }

            }
        }
        */

        cout << x*2 << endl;
    }
}

B - Yet Another Crosses Problem

题意:给出一个图,里面有白块和黑块,现在可以把白块涂成黑的,问最少操作几步可以涂出一个题目所述的十字架

做法:‘.'指的是白色,先遍历查这一行有多少白色,这一列有多少白色,之后再遍历一遍,比较结果就行,注意的是如果中心点是白的,答案得减一(因为上面遍历查的时候并没有算中心点)

代码:

//去吧马里奥!把AC公主救回来!
//        ********
//       ************
//       ####....#.
//     #..###.....##....
//     ###.......######
//        ...........
//       ##*#######
//    ####*******######
//   ...#***.****.*###....
//   ....**********##.....
//   ....****    *****....
//     ####        ####
//   ######        ######
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<map>
#include<sstream>
#include<cstring>
#include<vector>
#include<iomanip>
#include<queue>
#include<set>
#define LL long long
#define _64 __int64
const double PI = atan(1.)*4.;
using namespace std;
const int N = 5e4+1;
string st[N];
int h[N],l[N];
int main(){
    int q;
    cin >> q;
    while(q--){
        int n,m;
        cin >> n >> m;
        for(int i = 0;i < n;i++){
            cin >> st[i];
        }
        int ans;
        ans= 0;
        int minx = 500;
        for(int i = 0;i <n;i++){
            for(int j = 0;j < m;j++){
                if(st[i][j] == '.'){
                    h[i]++;
                    l[j]++;
                }
            }
        }
        for(int i = 0;i < n;i++){
            for(int j = 0;j < m;j++){

                if(st[i][j] == '.'){
                    ans = -1;
                }else{
                    ans = 0;
                }
                if(h[i]+l[j]+ans<minx){
                    minx = h[i]+l[j]+ans;
                }
            }
        }

        cout << minx << endl;

    }
}

C - From S To T

题意:三个字符串,从p里取字符放到s里的任意位置,问能不能让s成为t

做法:一开始读错题了,后来差点把人绕死,一开始以为s的位置也可以换,然后就用的统计字符数量的办法,结果不对,就加了一个判断函数,判断s是不是t的字串,这样就保证了s的顺序不需要变就可以成为t,把这个判断条件加上就可以过了,因为代码是后期缝补的,所以乱的一批……

代码:

//去吧马里奥!把AC公主救回来!
//        ********
//       ************
//       ####....#.
//     #..###.....##....
//     ###.......######
//        ...........
//       ##*#######
//    ####*******######
//   ...#***.****.*###....
//   ....**********##.....
//   ....****    *****....
//     ####        ####
//   ######        ######
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<map>
#include<sstream>
#include<cstring>
#include<vector>
#include<iomanip>
#include<queue>
#include<set>
#define LL long long
#define _64 __int64
const double PI = atan(1.)*4.;
using namespace std;

bool com(string s,string t){
    int j = 0;
    for(int i = 0; i < t.length(); i++) {
        for (j; j < s.length(); j++) {
            if (t[i] == s[j]) {
                j++;
                break;
            }else{
                break;
            }
        }

    }
    if(j == s.length()) {
        return 1;
    }else{
        return 0;
    }

}



int main(){
    int q;
    cin >> q;
    while(q--){
        string s,t,p;
        cin >> s >> t >> p;
        string x;
        x = s+p;
        int xxx = 0;
        xxx = com(s,t);
        //cout <<xxx<<endl;

        int a[300];
        memset(a,0,sizeof(a));
        for(int i = 0;i < x.size();i++){

            char l;
            l = x[i];
            //cout << l << endl;
            a[l]++;
        }
        int b[300];
        memset(b,0,sizeof(b));
        for(int i = 0;i < t.size();i++){
            char k;
            k = t[i];
            b[k]++;
        }
        int flag = 1;
        for(int i = 0;i <300;i++){
            if(b[i] <= a[i]){
                flag = 1;
            }else{
                flag = 0;
                break;
            }
        }
        if(flag == 1 && xxx == 1){

            cout << "YES" <<endl;
        }else{
            cout << "NO" << endl;
        }

    }
}

E - Buying a TV Set

题意:有一面长宽a,b的墙,需要买一台电视挂上,电视的宽高比需要满足x/y,求满足要求的w/h有几对

做法:数据范围太大了,不能暴力了,所以先把x/y化简(用gcd),之后分别拿a和b除以化简之后的数,取其中最小的,就是至少满足的对数,大的那个数是不一定满足的。

代码:

//去吧马里奥!把AC公主救回来!
//        ********
//       ************
//       ####....#.
//     #..###.....##....
//     ###.......######
//        ...........
//       ##*#######
//    ####*******######
//   ...#***.****.*###....
//   ....**********##.....
//   ....****    *****....
//     ####        ####
//   ######        ######
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<map>
#include<sstream>
#include<cstring>
#include<vector>
#include<iomanip>
#include<queue>
#include<set>
#define LL long long
#define _64 __int64
const double PI = atan(1.)*4.;
using namespace std;


int GCD(int x, int y)
{
    int z = y;
    while(x%y!=0)
    {
        z = x%y;
        x = y;
        y = z;
    }
    return z;
}

int main(){
    LL a,b,x,y;
    cin >> a >> b >> x >> y;
    LL num;
    num = GCD(x,y);
    x = x / num;
    y = y / num;
    LL i,j;
    i = a / x;
    j = b / y;
    cout << min(i,j) << endl;
}

 

posted @ 2020-10-10 11:02  CCCCrack  阅读(147)  评论(0)    收藏  举报