Atcoder ABC 166 B-D (B簡單模擬, C 思維 , D 枚舉) 交一發再說

B - Trick or Treat

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

題意:

給你N個Snuke ,問你有哪一間Snuke是沒有小吃的。

思路:

  1. 有小吃就記錄一下。
  2. 最後遍歷一遍就知道有幾間Snuke沒有小吃。

AC

#include <iostream>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
const int maxn=1e3+10;
int a[maxn];
int main()
{
    int n,k,d,s;
    cin>>n>>k;
    For(i,1,k)
    {
        cin>>d;
        For(j,1,d)
        {
            cin>>s;
            a[s]++;
        }
    }
    int ans=0;
    For(i,1,n)if(a[i]==0)ans++;
    cout<<ans<<endl;
    return 0;
}

C - Peaks

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

題意:

給你一個圖,並且每個點有權值,good點是,它是一個極大值。(連通塊裏只有一個點的話,它本身就是極大值)

思路1:

直接模擬。(我是先設所有點都滿足,如果一個點有一次是下位點,那麼就ans–,且標記一下,還要考慮高度相等的情況)

AC

#include <iostream>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
const int maxn=1e5+10;
int h[maxn],vis[maxn];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    For(i,1,n)cin>>h[i];
    int ans=n;
    For(i,1,m)
    {
        int a,b;
        cin>>a>>b;
        if(h[a]==h[b])
        {
            if(!vis[a])ans--,vis[a]=1;
            if(!vis[b])ans--,vis[b]=1;
            continue;
        }
        if(h[a]>h[b])a=b;
        if(!vis[a])
        {
            vis[a]=1;
            ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

思路2:(官方)

  1. 由於是極大值,就考察一個點的每個鄰接點中最高的(如果有的話)和它本身的高度對比。
  2. 這裏用一個數組預處理。

AC(官方)

#include <iostream>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
const int maxn=1e5+10;
int h[maxn];
int ma[maxn];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    For(i,1,n)cin>>h[i];
    For(i,1,m)
    {
        int a,b;
        cin>>a>>b;
        ma[a]=max(ma[a],h[b]);
        ma[b]=max(ma[b],h[a]);
    }
    int ans=0;
    For(i,1,n)ans+=h[i]>ma[i];
    cout<<ans<<endl;
    return 0;
}

D - I hate Factorization

在這裏插入圖片描述
在這裏插入圖片描述

題意:

很明顯。

思路:

枚舉(1000e5也就1e15很大了,超過x了是可以接受的)

反思:

  1. contest時,以爲枚舉有漏洞,以爲每個點都應該滿足式子(事實只有一些點是滿足的),不要想太多了,有了大思路,先碼一遍,交一發再說

AC

#include <iostream>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
typedef long long ll;
ll pow(ll a)
{
    return a*a*a*a*a;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll x,a,b;
    int flag=0;
    cin>>x;
    For(i,-200,200)
    {
        For(j,-200,200)
        {
            if(pow((ll)i)-pow((ll)j)==x)
            {
                flag=1;
                cout<<i<<' '<<j<<endl;
            }
        }
        if(flag)break;
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章