分析:这道题一个一个枚举都能有70分......

前60分可以用中国剩余定理搞一搞.然而并没有枚举分数高......考虑怎么省去不必要的枚举,每次跳都只跳a的倍数,这样对前面的式子没有影响,为了使得这个倍数最小从而不会WA掉,每次跳最小公倍数就可以了.

60分代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; ll mod[], a[], ans, M = ; void exgcd(ll a, ll b, ll &x, ll &y)
{
if (!b)
{
x = ;
y = ;
return;
}
exgcd(b, a % b, x, y);
ll t = x;
x = y;
y = t - (a / b) * y;
return;
} int main()
{
scanf("%lld%lld%lld%lld%lld%lld%lld%lld", &mod[], &a[], &mod[], &a[], &mod[], &a[], &mod[], &a[]);
for (int i = ; i <= ; i++)
M *= mod[i];
for (int i = ; i <= ; i++)
{
ll mi = M / mod[i];
ll x, y;
exgcd(mi, mod[i], x, y);
ans = (ans + a[i] * mi * x) % M;
}
if (ans < )
ans += M;
printf("%lld\n", ans); return ;
}

100分代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; ll mod[], a[], gcd, lcm, ans; ll GCD(ll x, ll y)
{
if (!y)
return x;
return GCD(y, x % y);
} int main()
{
scanf("%lld%lld%lld%lld%lld%lld%lld%lld", &mod[], &a[], &mod[], &a[], &mod[], &a[], &mod[], &a[]);
lcm = mod[];
gcd = mod[];
ans = a[];
for (int i = ; i <= ; i++)
{
while (ans % mod[i] != a[i])
ans += lcm;
gcd = GCD(gcd, mod[i]);
lcm = lcm / gcd * mod[i];
}
printf("%lld\n", ans); return ;
}

noip模拟赛 同余方程组的更多相关文章

  1. NOIP模拟赛 6.29

    2017-6-29 NOIP模拟赛 Problem 1 机器人(robot.cpp/c/pas) [题目描述] 早苗入手了最新的Gundam模型.最新款自然有着与以往不同的功能,那就是它能够自动行走, ...

  2. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  3. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  4. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  5. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

  6. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

  7. 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...

  8. 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...

  9. CH Round #58 - OrzCC杯noip模拟赛day2

    A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...

随机推荐

  1. codeforces 949B A Leapfrog in the Array

    B. A Leapfrog in the Array time limit per test 2 seconds memory limit per test 512 megabytes input s ...

  2. [Django基础] gunicorn启动django时静态文件的加载

    目前在用nginx+gunicorn对django进行部署 当我用gunicorn -w 4 -b 127.0.0.1:8080 myproject.wsig:application启动django时 ...

  3. 字典(Trie树)

    4189 字典  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master     题目描述 Description 最经,skyzhong得到了一本好厉害的字典,这个 ...

  4. [Swift通天遁地]二、表格表单-(6)创建美观的表格弹性下拉刷新效果

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. 【BZOJ3110】[ZJOI2013]K大数查询(整体二分)

    题目: BZOJ3110 分析: 整体二分模板题-- 先明确一下题意:每个位置可以存放多个数,第一种操作是"加入 (insert) "一个数而不是"加上 (add) &q ...

  6. Elasticsearch之sense插件安装之后的浏览详解

    前提博客是 Elasticsearch之sense插件的安装(图文详解) 立马,可以看到 http://192.168.80.145:5601/app/sense 以后更新

  7. C#中 分层 显示数据库中多表的数据信息

    如下图,要实现将三个表中的内容加载到同一个窗体中,该怎么来实现呢? 要实现上面的查询结果,我们就要从Student表中拿到学生姓名,从Subject表中拿到科目名称,从StudentResult表中拿 ...

  8. 如何调用com组件中包含IntPtr类型参数的函数

    背景 公司的支付平台最近对接了西安移动的支付接口,接口中签名的方法是对方提供了一个com组件,组件中包含了一个签名的方法和一个验签的方法,注册了签名之后,在vs中进行了引用,引用之后,查看组件的定义如 ...

  9. [ SDOI 2009 ] HH的项链 & [ HEOI 2012 ] 采花

    \(\\\) \(Description\) 给出一个长为\(N\)的序列,\(M\)次询问区间\([L_i,R_i]\)内不同数字的个数. \(N\in [1,5\times 10^4]\),\(M ...

  10. jQuery中国各个省份地图分部代码

    jQuery中国各个省份地图分部代码 在线演示本地下载