zoukankan      html  css  js  c++  java
  • BZOJ3751 NOIP2014 解方程(Hash)

    题目链接  BZOJ3751

    这道题的关键就是选取取模的质数。

    我选了4个大概几万的质数,这样刚好不会T

    然后统计答案的时候如果对于当前质数,产生了一个解。

    那么对于那些对这个质数取模结果为这个数的数也要统计进答案。

    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define rep(i, a, b)	for (int i(a); i <= (b); ++i)
    #define dec(i, a, b)	for (int i(a); i >= (b); --i)
    
    const int N = 2e4 + 10;
    const int M = 1e6 + 10;
    
    const int p[6] = {0, 26833, 15259, 19249, 26681};
    
    int n, m;
    char ch[N];
    int a[10][N], fg;
    int s[M], len, ans;
    
    int main(){
    
    	scanf("%d%d", &n, &m);
    	rep(i, 0, n){
    		scanf("%s", ch + 1);
    		len = strlen(ch + 1);
    		fg  = 1;
    		if (ch[1] == '-') fg = -1, ch[1] = '0';
    		rep(j, 1, 4){
    			rep(k, 1, len) a[j][i] = (a[j][i] * 10 + ch[k] - 48) % p[j];
    			a[j][i] = (a[j][i] * fg + p[j]) % p[j];
    		}
    	}
    
    	rep(i, 1, 4){
    		rep(j, 0, p[i] - 1){
    			int x = a[i][n];
    			dec(k, n - 1, 0) x = (x * j + a[i][k]) % p[i];
    			if (!x) for (int k = j; k <= m; k += p[i]) ++s[k];
    		}
    	}
    
    	ans = 0;
    	rep(i, 1, m) if (s[i] == 4) ++ans;
    	printf("%d
    ", ans);
    	rep(i, 1, m) if (s[i] == 4) printf("%d
    ", i);
    	return 0;
    }
    

      

  • 相关阅读:
    Sqlserver日期函数应用
    SSRS匿名访问
    SSAS动态添加分区(一)
    BI就是报表?
    CreateEvent函数/多线程/c++
    字符编码介绍
    Win7 64下Visual C++ 6.0不兼容
    Winpcap安装,Cannot open include file 'pcap.h'
    PPT开发 * .pps 文件类型
    Visual Assist X 工具栏不显示 toolbar
  • 原文地址:https://www.cnblogs.com/cxhscst2/p/7913292.html
Copyright © 2011-2022 走看看