ARC109

A
(quad)直接建图,或者数学做法都可以。

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<climits>
#include<sstream>
#include<fstream>
using namespace std;
#include<queue>

const int N = 210;
const int M = 2e4 + 10;

int head[N] , net[M] , vis[M] , wigh[M];
int tot = 1;

inline void add(int u , int v , int w)
{
    tot++;
    net[tot] = head[u];
    head[u] = tot;
    vis[tot] = v;
    wigh[tot] = w;
}

int dis[N];
bool book[N];

queue<int> q;

inline int spfa(int s , int e)
{
    memset(dis , 0x3f , sizeof(dis));
    book[s] = 1 , dis[s] = 0;
    q.push(s);
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        book[u] = 0;
        for(register int i = head[u] ; i ; i = net[i])
        {
            int v = vis[i];
            int w = wigh[i];
            if(dis[v] > dis[u] + w)
            {
                dis[v] = dis[u] + w;
                if(book[v] == 0)
                {
                    q.push(v);
                    book[v] = 1;
                }
            }
        }
    }
    return dis[e];
}

signed main()
{
    int a , b , x , y;
    cin >> a >> b >> x >> y;
    for(register int i = 1 ; i <= 99 ; i++)
    {
        add(i , 100 + i , x);
        add(100 + i , i , x);
        add(100 + i , i + 1 , x);
        add(i + 1 , 100 + i , x);
        add(i , i + 1 , y);
        add(i + 1 , i , y);
        add(100 + i , 100 + i + 1 , y);
        add(100 + i + 1 , 100 + i , y);
    }
    add(100 , 200 , x);
    add(200 , 100 , x);
    cout << spfa(a , 100 + b);
    return 0;
}

B
(quad)贪心,转换问题为找到最大的(x)使(1+2+...+xle n+1),然后(n-x+1)为答案。
(quad)直接二分即可。

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<climits>
#include<sstream>
#include<fstream>
using namespace std;
#define int __int128

inline int read()
{
    char c;
    int flag = 1;
    while((c = getchar()) < '0' || c > '9')
    {
        if(c == '-')
        {
            flag = -1;
        }
    }
    int count = c - '0';
    while((c = getchar()) >= '0' && c <= '9')
    {
        count *= 10;
        count += c - '0';
    }
    return count * flag;
}

inline void print(int x)
{
    if(x < 0)
    {
        x = -x;
        putchar('-');
    }
    if(x > 9)
    {
        print(x / 10);
    }
    putchar(x % 10 + '0');
}

int n;

inline int check(int x)
{
    if(((1 + x) * x / 2) <= n + 1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

signed main()
{
    n = read();
    int l = 1 , r = n;
    int ans = 0;
    while(l <= r)
    {
        int mid = (l + r) >> 1;
        if(check(mid))
        {
            ans = mid;
            l = mid + 1;
        }
        else
        {
            r = mid - 1;
        }
    }
    print(n - ans + 1);
    return 0;
}

C
(quad)不太想翻译这个题面,所以没做。

$——byquad wanwanjiuhao7744$
原文地址:https://www.cnblogs.com/wanwanjiuhao7744/p/15120810.html