zoukankan      html  css  js  c++  java
  • NOIP2014 解方程

    题目传送门

    第一次用秦九韶公式,有点小激动(然而并不)


    可以很暴力的从(1)(m)依次代数。因为用了秦九韶,计算一次是(O(n))的,总复杂度(O(nm))
    高精其实没什么必要,我们直接模一个大质数来判断就可以。当它们在模(p)意义下为(0),就认为原式为(0),因为懒,我只用了一个质数。保险起见,建议使用(geq2)个质数
    为了读入(a),强制使用快读,读入时取模

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define inf 0x7ffffff
    #define gc getchar();
    using namespace std;
    #define mod 2147483647
    #define LL long long
    LL read(){LL k=0,f=1;char c=gc;while(!isdigit(c)){if(c=='-')f=-1;c=gc;}while(isdigit(c)){k=(k*10+c-48)%mod;c=gc;}return k*f;}
    LL a[110],n,m;
    LL calc(int x){  //秦九韶
    	LL sum=a[n];
    	for(int i=n;i>=1;i--)
    	  sum=(sum*x+a[i-1])%mod;
    	return sum;
    }
    int ans[1000010],top;
    int main(){
    	n=read(),m=read();
    	for(int i=0;i<=n;i++) a[i]=read();
    	for(int i=1;i<=m;i++){
    		if(!calc(i)) ans[++top]=i;
    	}
    	printf("%d
    ",top);
    	for(int i=1;i<=top;i++)
    	  printf("%d
    ",ans[i]);
        return 0;
    }
    
  • 相关阅读:
    Python startswith()函数 与 endswith函数
    Oracle spool 小结
    表空间(TableSpace)
    Python logger模块
    Mysql rpm安装
    Python json与pickle
    Python 生成器总结
    Python 装饰器的总结
    eclipse 乱码问题总结
    Eclipse 中出现红色下划波浪线与红色感叹号
  • 原文地址:https://www.cnblogs.com/morslin/p/11854957.html
Copyright © 2011-2022 走看看