zoukankan      html  css  js  c++  java
  • Topcoder SRM 657DIV2

    前言:

          像我这样一直在DIV2的弱菜。。不知道说什么了。

    A:一定判断有8个‘R’,每行 每列只有一个

    B题:大概是  int E,int EM,int M,int MH,int H

    然后EM可以给值到E,M,MH可以给值到H,M;

    我的做法二分,然后判断。

    C:遇到数论就跪。。

    求a*x^2+b*x+c=0 (mod p);p=10^9;

    不满足输出-1 a,b,c,x 都在【0,999999999】;

    首先p=10^9本来就很特殊,所以从这里考虑

    p=2^9*5^9;

    f[x]=a*x^2+b*x+c;

    先求出f[x1]=0 (mod 2^9);

    然后 f[x1+2^9*k]=0 (mod 5^9);

    因为求也能f[x1+2^9*k】=0(mod 2^9);所以满足

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 #include <cstring>
     7 #include <vector>
     8 
     9 #define ll long long
    10 #define ull unsigned long long
    11 using namespace std;
    12 
    13 #define mod 1000000000
    14 #define N 999999999
    15 
    16 class PolynomialRemainder {
    17     public:
    18 
    19     int findRoot(int a, int b, int c) {
    20     ll x=0;
    21     ll mod1=1<<9;
    22     ll mod2=1;
    23     for (int i=1;i<=9;i++) mod2*=5;
    24 
    25     for (x=0;x<mod1;x++)
    26     if ((x*x*a+b*x+c) % mod1 ==0) break;
    27 
    28     if (x==mod1) return -1;
    29 
    30     for (;x<mod1*mod2;x+=mod1)
    31     {
    32          if ((x*x%mod2*a+b*x+c) % mod2 ==0) return x;
    33     }
    34     return -1;
    35     }
    36 };

    所以关键是10^9的分化。

  • 相关阅读:
    2. Add Two Numbers
    1. Two Sum
    22. Generate Parentheses (backTracking)
    21. Merge Two Sorted Lists
    20. Valid Parentheses (Stack)
    19. Remove Nth Node From End of List
    18. 4Sum (通用算法 nSum)
    17. Letter Combinations of a Phone Number (backtracking)
    LeetCode SQL: Combine Two Tables
    LeetCode SQL:Employees Earning More Than Their Managers
  • 原文地址:https://www.cnblogs.com/forgot93/p/4464026.html
Copyright © 2011-2022 走看看