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

    传送门

    还有这种操作?

    我看到这道题的时候想到暴力枚举,不过a的范围极大令人头疼。Ssy说他要用Python然后他T了

    不过后来发现,因为我们要解的方程左边是等于0的,所以我们可以直接把所有的a对于某一个数取模,这个在读入的时候就能处理,之后直接暴力枚举m用秦九韶算法硬算即可。

    这都是什么神仙操作

    看一下代码。

    // luogu-judger-enable-o2
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<iostream>
    #include<cmath>
    #include<set>
    #include<queue>
    #define rep(i,a,n) for(int i = a;i <= n;i++)
    #define per(i,n,a) for(int i = n;i >= a;i--)
    #define enter putchar('
    ')
    
    using namespace std;
    typedef long long ll;
    const int M = 1000005;
    const ll INF = 1e17+9;
    const ll mod = 19260817;
    
    ll read()
    {
        ll ans = 0,op = 1;
        char ch = getchar();
        while(ch < '0' || ch > '9')
        {
        if(ch == '-') op = -1;
        ch = getchar();
        }
        while(ch >= '0' && ch <= '9')
        {
        ans *= 10;
        ans += ch - '0';
        ans %= mod;
        ch = getchar();
        }
        return ans * op;
    }
    
    ll n,m,a[105],cnt,ans[M];
    
    ll calc(ll x)
    {
        ll ans = 0;
        per(i,n,0) ans *= x,ans += a[i],ans %= mod;
        return ans;
    }
    
    int main()
    {
        n = read(),m = read();
        rep(i,0,n) a[i] = read();
        rep(i,1,m)
        {
        ll k = calc(i);
        if(k == 0) ans[++cnt] = i;
        }
        printf("%lld
    ",cnt);
        rep(i,1,cnt) printf("%lld
    ",ans[i]);
        return 0;
    }
    View Code
  • 相关阅读:
    软考收获
    寻找她(指令寻址)——(软考六)
    算法探究——(软考四)
    Shell排序——软考(五)
    Java String类源码
    Java 抽象类详解
    Spring IOC Container
    Tomcat的架构
    Spring与Web框架(例如Spring MVC)漫谈——关于Spring对于多个Web框架的支持
    HTML form表单中action的正确写法
  • 原文地址:https://www.cnblogs.com/captain1/p/9834455.html
Copyright © 2011-2022 走看看