分析:这道题一个一个枚举都能有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. Java中JPS命令监控

    很多人在学习java的时候只是对java粗略的学了一遍,很少有人能了解jvm层面的一些东西,比如我们想看目前有多少个java进程,可以在命令行执行jps.下面我们来说说jps的一些详细的用法. jps ...

  2. NS2学习笔记(三)

    代理(Agents) 代理是网络层数据包产生和使用的端点,用于实现多层的协议.Agent类部分用OTcl实现,部分用C++实现.C++的代码在~ns/agent.cc和~ns/agent.h中,OTc ...

  3. day01_12/11/2016_Spring入门PPT

    s1 s2 s3 s4 s5 s6 s7 s8 IOC1 IOC2 入门编写1 入门编写2 入门编写3 入门编写4---心得

  4. Singleton.java.ft not found 相关错误的解决办法

    Entry fileTemplates//Singleton.java.ft not found in C:/Users/admin/Desktop/android-studio/lib/resour ...

  5. js技巧(一)

    1.文档入口函数 window.onload = function () { //code 将会在页面的全部代码执行完成之后再去执行. } 2.弹窗   alert()   警告窗   confirm ...

  6. CSS——font

    行高的量取方式: 1.第一行可设置margin-top值.然后将第一文字顶部到第二行文字顶部的值作为行高的值(要注意对齐方式) 2.将 3.电视上 font:12px/1.5//字体12px,行高1. ...

  7. 【译】x86程序员手册02 - 基本的程序模式

    Chapter 2 -- Basic Programming Model: 基本的程序模式 Introduces the models of memory organization. Defines ...

  8. CSS3:变换和动画

    <html> <style> .container{ -webkit-perspective: 800; -webkit-perspective-origin: 50% 40% ...

  9. Web 服务器与应用服务器的区别是什么?

    不太严谨的说法:web服务器就是负责接收用户的Request,然后响应html等给客户浏览器.应用服务器处理一些业务逻辑等. 作者:luo链接:https://www.zhihu.com/questi ...

  10. Dispatch Queues 线程池

    Dispatch Queues Dispatch queues are a C-based mechanism for executing custom tasks. A dispatch queue ...