zoukankan      html  css  js  c++  java
  • POJ_2939 Flavius Josephus Reloaded

      内部赛遇到这道题SDUT_2369,map写TLE。话说校内OJ很奇芭的把队友的判成AC,把我的判成TLE。最后队长总结说这是人品问题。。。汗 =_=///

    赛后用hash写了一下,关键要处理冲突,用挂链法写的。最后自己看了一下,怎么看怎么像邻接表。或许可以把这个题改一下弄个不错的图论题,哈

    poj 1235 + ms, sdutoj 578 + ms。我们的服务器还是很给力的。

    渣代码:

    View Code
     1 #include <vector>
    2 #include <list>
    3 #include <map>
    4 #include <set>
    5 #include <queue>
    6 #include <deque>
    7 #include <stack>
    8 #include <bitset>
    9 #include <algorithm>
    10 #include <functional>
    11 #include <numeric>
    12 #include <utility>
    13 #include <sstream>
    14 #include <iostream>
    15 #include <iomanip>
    16 #include <cstdio>
    17 #include <cmath>
    18 #include <cstdlib>
    19 #include <ctime>
    20 #include <cstring>
    21
    22 using namespace std;
    23
    24 const int MOD = 1000007;
    25 typedef long long ll;
    26 struct node {
    27 long long n;
    28 int cnt;
    29 int next;
    30 } mp[MOD];
    31
    32 int head[MOD], t;
    33
    34 void init() {
    35 for(int i = 0; i < MOD; ++i) head[i] = 0;
    36 t = 1;
    37 }
    38
    39 void add(int u, long long v) {
    40 mp[t].n = v; mp[t].cnt = 1;
    41 mp[t].next = head[u]; head[u] = t++;
    42 }
    43
    44 int find(int t, long long x) {
    45 int i;
    46 for(i = head[t]; i; i = mp[i].next) {
    47 if(mp[i].n == x) {
    48 mp[i].cnt++;
    49 return mp[i].cnt;
    50 }
    51 }
    52 return 0;
    53 }
    54
    55 int main() {
    56 //freopen("data.in", "r", stdin);
    57
    58 ll x;
    59 int n, a, b, u;
    60 int cnt;
    61 while(scanf("%d", &n), n) {
    62 scanf("%d%d", &a, &b);
    63 init();
    64 x = b%n; cnt = 0;
    65
    66 while(1) {
    67 u = find(x%MOD, x);
    68 if(u == 2) cnt++;
    69 if(u == 3) break;
    70 if(!u) {
    71 add(x%MOD, x);
    72 }
    73 x = (((a*x)%n*x) + b)%n;
    74 }
    75 printf("%d\n", n - cnt);
    76 }
    77 return 0;
    78 }



  • 相关阅读:
    Power of Cryptography(用double的泰勒公式可行分析)
    Radar Installation(贪心)
    The Pilots Brothers' refrigerator(dfs)
    Flip Game(dfs)
    Connect the Cities(MST prim)
    Constructing Roads (MST)
    suoi16 随机合并试卷 (dp)
    suoi14 子树查找 (dfs)
    nowcoder106I Neat Tree (单调栈)
    luogu2296 [NOIp2014]寻找道路 (bfs)
  • 原文地址:https://www.cnblogs.com/vongang/p/2415912.html
Copyright © 2011-2022 走看看