2020 ACM新生赛(绝望赛)

hr师哥的题解奉上
1616.Arithmetic Sequence
在这里插入图片描述
题意:数列为等差数列,给你等差数列的和,求当数列数最少时的数列(坑点:第一行说数列可以为一个数)
所以直接输入输出就行

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <sstream>
#include <map>
#include <set>
typedef long long ll;
using namespace std;

int main()
{
    
    
    ll x;
    cin>>x;
    cout<<x;
}





1622.蓝精精的浏览器
在这里插入图片描述
题意是:先打开一个网页,再进行一堆操作,当操作为VISIT时,就打开另一个网站,当操作为BACK时就返回上一个网站,当操作为FORWARD时就访问下一个网站,当操作为QUIT时就结束操作

通过这个样例能看出来这个题的坑点是,假如你连续VISITl两次,又返回一次,这个时候再访问了一个新的网址,你就不能返回到当时第二个VISIT 的网址

要用两个栈进行解决

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <sstream>
#include <map>
#include <set>
typedef long long ll;
using namespace std;


string cz;//操作
string wb;//网址
stack<string> s1;
stack<string> s2;

int main()
{
    
    

    s1.push("http://www.acm.org/");
    while(cin>>cz)//输入操作
    {
    
    
        if(cz == "QUIT")
        {
    
    
            break;//结束操作
        }
        else if(cz == "VISIT")
        {
    
    
            while (!s2.empty())//这个就是那个特殊情况,要把s2里面的都扔出去
                s2.pop();
            cin>>wb;
            s1.push(wb);
            cout<<s1.top()<<endl;

        }
        else if(cz == "BACK")
        {
    
    

            if(s1.size() != 1)//判断是不是能进行back操作,因为你要是s1中只有一个元素, 那就不能进行back返回到上个网址上
            {
    
    
                s2.push(s1.top());//就得把1的当前网址赛到2里面,并把他扔出去,然后显示1里面的下个元素
                s1.pop();
                cout<<s1.top()<<endl;
            }
            else
                cout<<"Ignored"<<endl;
        }
        else if(cz == "FORWARD")
        {
    
    
            if(!s2.empty())//判断是否出界
            {
    
    
                s1.push(s2.top());
                s2.pop();
                cout<<s1.top()<<endl;
            }
            else
                cout<<"Ignored"<<endl;
        }

    }
    return 0;
}




1623.闷声发大财

在这里插入图片描述

在这里插入图片描述

补题的时候才发现他是个签到题,就是卡你的大小

题意:有n*n的方阵,输入m个记者坐标,每个坐标的行与列都会被看见,依次输出记者看不见的坐标的数量

用了点数学 的小思维,就是方阵中去掉数量不一的行与列去计算剩下的格数,方法就是:把每个去掉的行或列移到一个地方去,就比如行都移动到上方,列都移动到左面,然后剩下的就可以用矩形面积公式计算格子数

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int M = (int)1e7;
const int N = (int)1e5;
const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
const ll mod = (ll)998244353;

int ar[N + 5];//行
int br[N + 5];//列
int acnt = 0;//被标记的行数
int bcnt = 0;//被标记的列数

int main()
{
    
    
    int n, m, a ,b;
    cin>>n>>m;
    for(int i = 1; i <= m; i++)
    {
    
    
        cin>>a>>b;
        if(!ar[a])//判断第a行是否被标记,如果没被标记就标记一下,并对标记的行数加一
        {
    
    
            acnt++;
            ar[a] = 1;
        }
        if(!br[b])//判断第b行是否被标记,如果没被标记就标记一下,并对标记的列数加一
        {
    
    
            bcnt++;
            br[b] = 1;

        }
        printf("%lld%c", 1ll * (n - acnt) * (n - bcnt), i == m ? '\n' : ' ');//这个输出格式很重要,背下来就好,而且在你输出的不是经过定义longlong的变量,而会超出int范围时,就得写1ll  *,意思是将其转换成longlong形式的,就算其中的因子定义了longlong也没有用(我就是这样wa了好多次)
    }
    return 0;


}


1625.星球大战1
在这里插入图片描述

题意:n*n的方阵,你在(1,1)这个点,然后方阵上的每一个点都可能有飞机攻击你,但攻击的激光是直线的,所以不能让他们攻击到友方,求能有的飞机的数量最多是多少个

我比赛的时候一个个草图的画,来找规律,貌似是找到了,但是却wa了,这有个恶心,可能是图越大后面的就会出问题 吧,后来看师哥写的题解,才明白可以用最大公因数来求解。
就是如果这个点的横纵坐标的最大公因数为1,那么这个点就可以放飞机,其实道理很简单,你在一个地方放飞机,(1,1)与这个点连线的后面 的所有坐标都不能放飞机,不然就会误伤队友。(我当时可能找规律找上瘾了,就没往这方面想)

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <sstream>
#include <map>
#include <set>
typedef long long ll;
using namespace std;

int gcd(int a, int b)//最大公因数
{
    
    
    if(b)
        return gcd(b, a % b);
    else
        return a;
}

int main()
{
    
    
    int n, m;
    cin>>n;
    if(n == 1)//比较特殊,是1时就只有他自己,没有飞机
    {
    
    
        cout<<0;
        return 0;

    }
    else
    {
    
    
        int ans = 3;//从二开始就是三个飞机
        for(int i = 1; i < n; i++)
        {
    
    
            for(int j = 1; j < n; j++)
            {
    
    
                if(gcd(i, j) == 1)
                    ans ++;
           //     ans+=(gcd(i, j) == 1);
            }
        }
        cout<<ans-1;
    }
    return 0;
}





猜你喜欢

转载自blog.csdn.net/weixin_51216553/article/details/109786482