暫存

約瑟夫環

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

const int N = 1000 + 10;

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int ans = 0;
    for(int i = 2; i <= n; i++) ans = (ans + k) % i;
    printf("%d\n", ans + 1);
    return 0;
}

染色

bool dfs(int v, int x)
{
    color[v] = x;
    for(int i = head[v]; ~i; i = g[i].next)
    {
        int u = g[i].to;
        if(color[v] == color[u]) return false;
        if(! color[u] && !dfs(u, -color[v])) return false;
    }
    return true;
}
bool bfs(int v, int x)
{
    queue<int> que;
    que.push(v), color[v] = x;
    while(! que.empty())
    {
        int v = que.front(); que.pop();
        for(int i = head[v]; ~i; i = g[i].next)
        {
            int u = g[i].to;
            if(color[v] == color[u]) return false;
            if(! color[u]) color[u] = -color[v], que.push(u);
        }
    }
    return true;
}

自造隨機數(不會重複)

inline int random(){
    static int seed=703; //seed可以隨便取
    return seed=int(seed*48271LL%2147483647);
}
發佈了601 篇原創文章 · 獲贊 25 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章