#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause") #else #define D_e_Line ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; int f[3000007]; int main(){
int n, m;
io >> n >> m;
R(i,1,m){
int x, y, a, b;
io >> x >> y >> a >> b;
R(j,1,y)
f[1ll * (1ll * a * j + b) % n] += x;
} int flag = false;
while(!flag || f[0] > 1){
R(i,0,n - 1){
if(f[i] > 1){
f[(i + 1) % n] += f[i] - 1;
f[i] = 1;
}
}
flag = true;
} R(i,0,n){
if(f[i] == 0){
printf("%d", i);
return 0;
}
} return 0;
}

Luogu3090 [USACO13NOV]空荡荡的摊位Empty Stalls (动态规划)的更多相关文章

  1. [USACO13NOV]空荡荡的摊位Empty Stalls

    题目描述 Farmer John's new barn consists of a huge circle of N stalls (2 <= N <= 3,000,000), numbe ...

  2. 解题:USACO13NOV Empty Stalls

    题面 当然可以用并查集做,不过你需要按秩合并+路径压缩(才可能过),因为数据范围十分不友好...... USACO的官方做法更为优秀.首先题目告诉我们牛们加入的前后顺序不影响结果(自己证明也很容易,显 ...

  3. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  4. USACO 2013 November Contest Gold 简要题解

    Problem 1. Empty Stalls 扫两遍即可. Problem 2. Line of Sight 我们发现能互相看见的一对点一定能同时看见粮仓的某一段.于是转换成有n段线段,问有多少对线 ...

  5. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

  6. [leetcode] 题型整理之动态规划

    动态规划属于技巧性比较强的题目,如果看到过原题的话,对解题很有帮助 55. Jump Game Given an array of non-negative integers, you are ini ...

  7. LEETCODE —— Unique Paths II [动态规划 Dynamic Programming]

    唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...

  8. Dungeon Game ——动态规划

    The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...

  9. ZOJ-3725 Painting Storages 动态规划

    题意:给定一个数N,表示有N个位置,要么放置0,要么放置1,问至少存在一个连续的M个1的放置方式有多少? 分析:正面求解可能还要考虑到重复计算带来的影响,该题适应反面求解.设dp[i][j]表示到前 ...

随机推荐

  1. 【Spring】AOP实现原理(二):Advisor获取

    @EnableAspectJAutoProxy @EnableAspectJAutoProxy注解可以用来开启AOP,那么就从@EnableAspectJAutoProxy入手学习一下Spring A ...

  2. 11.Firewalld防火墙

    Firewalld防火墙 目录 Firewalld防火墙 Firewalld概述 Firewalld Firewalld和iptables的关系 netfilter Firewalld/iptable ...

  3. Vue几行代码实现搜索功能

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Array 数组filter()方法,遍历数组返回符合条件的一个新数组

    <script> const arr = [ { id: 1, name: "aa", isDone: false }, { id: 2, name: "bb ...

  5. QT多线程的简单使用,主线程发一份数据,子线程收两份数据

    先看效果图,示例发送数据"Hello World" 主线程:0x16f54aeda20,另两个子线程分别是0x4f1baff690.0x4f1baff6a0 因为在子线程中加了20 ...

  6. 效率效率!如何使用Python读写多个sheet文件

    前言 怎么样使用Python提高自己的工作效率,今天就给大家分享这个吧. 我们经常用pandas读入读写excel文件,经常会遇到一个excel文件里存在多个sheet文件,这个时候,就需要一次性读取 ...

  7. 训练一个图像分类器demo in PyTorch【学习笔记】

    [学习源]Tutorials > Deep Learning with PyTorch: A 60 Minute Blitz > Training a Classifier   本文相当于 ...

  8. 配置Apollo阿波罗.net core 3.1 c#

    直接上代码: public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(a ...

  9. 数组容器(ArrayList)设计与Java实现,看完这个你不懂ArrayList,你找我!!!

    数组容器(ArrayList)设计与Java实现 本篇文章主要跟大家介绍我们最常使用的一种容器ArrayList.Vector的原理,并且自己使用Java实现自己的数组容器MyArrayList,让自 ...

  10. 开启apache2的ssl访问功能

    Ubuntu 20.04 1. Apache2默认安装的时候,ssl模块是不启用的.开启命令: $ sudo apt install apache2 #安装$ sudo a2enmod ssl #开启 ...