分析:这道题一个一个枚举都能有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. http协议的MP4文件播放问题的分析

    现在手上有两个链接 (1) http://202.108.16.173/cctv/video/8C/35/EB/E8/8C35EBE84E7B483C8741CF9A60154993/gphone/4 ...

  2. Java 集合 ArrayList 需要知道的几个问题

    问:Arraylist 的动态扩容机制是如何自动增加的?简单说说你理解的流程? 答:当在 ArrayList 中增加一个对象时 Java 会去检查 Arraylist 以确保已存在的数组中有足够的容量 ...

  3. 【Vijos1083/BZOJ1756】小白逛公园(线段树)

    [写在前面]TYC (Little White) 真是太巨啦! 题目: Vijos1083 分析: 一眼看上去就是线段树啊-- 然而当我这种蒟蒻兴高采烈地把线段树模板敲了一半,却发现一个问题: 这子区 ...

  4. web api初学

    据说web api的作用和wcf的一样,只是比wcf更简单而已,具体如何我也不清楚,毕竟不是做学术研究的,我只是通过简单的例子来学习web api.能做的只需要知其然,不必管其所以然.当然有兴趣的可以 ...

  5. 350 Intersection of Two Arrays II 两个数组的交集 II

    给定两个数组,写一个方法来计算它们的交集.例如:给定 nums1 = [1, 2, 2, 1], nums2 = [2, 2], 返回 [2, 2].注意:       输出结果中每个元素出现的次数, ...

  6. 【LeetCode】105 & 106 Construct Binary Tree from (Preorder and Inorder) || (Inorder and Postorder)Traversal

    Description: Given arrays recording 'Preorder and Inorder' Traversal (Problem 105) or  'Inorder and ...

  7. Microsoft SQL Server 2008/2012 Internals 一处疑问

    Kalen Delaney 等著的深入解析 Microsoft SQL Server 系列,享有盛誉,深入研读,是管窥深奥复杂之 SQL Server 的阶梯与门径.手头有 Microsoft SQL ...

  8. 10.Nodes and Bindings

    节点数据绑定 节点是构成Ventuz场景的基本元素.每个节点既属于图层.也属于层级或内容.既可以在图层编辑器,也可以在层级编辑器或内容编辑器中编辑. 内容节点包括资产描述(如材质.xml文件等).数字 ...

  9. 黑马程序员 关于c# windows窗体关闭时线程未能完全退出问题(专题一)

    <a href="http://edu.csdn.net"target="blank">ASP.Net+Android+IO开发S</a> ...

  10. node 第三方包学习

    时间格式化 moment var moment = require('moment'); moment().format();