CodeForces 785C Anton and Fairy Tale 二分】的更多相关文章

题意: 有一个谷仓容量为\(n\),谷仓第一天是满的,然后每天都发生这两件事: 往谷仓中放\(m\)个谷子,多出来的忽略掉 第\(i\)天来\(i\)只麻雀,吃掉\(i\)个谷子 求多少天后谷仓会空 分析: 分类讨论: 1. \(n \leq m\) 每天都会把谷仓放满,所以第\(n\)后会变空 2. \(n > m\) 前\(m\)天后谷仓还一直都是满的 第\(m+1\)天后还剩\(n-m-1\),第\(m+2\)天后还剩\(n-m-1-2\) 第\(m+i\)天后还剩\(n-m-\frac{…
二分. 如果$n≤m$,显然只能$n$天. 如果$n>m$,至少可以$m$天,剩余还可以支撑多少天,可以二分计算得到,也可以推公式.二分计算的话可能爆$long$ $long$,上了个$Java$. import java.math.BigInteger; import java.util.Scanner; public class Main { static Scanner cin = new Scanner(System.in); static BigInteger sum(BigInteg…
C. Anton and Fairy Tale 题目连接: http://codeforces.com/contest/785/problem/C Description Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there liv…
[题目链接]:http://codeforces.com/contest/785/problem/C [题意] 容量为n的谷仓,每一天都会有m个谷子入仓(满了就视为m);第i天 会有i只鸟叼走i个谷子; 问哪一天谷仓最早变成空的了; [题解] 当n<=m的时候,答案就为n; 当n>m的时候; 从第m+1天起谷仓的入库量比不上鸟的食量了; 会开始减少; 其中第m+1天减少m+1; 此后第m+2-依次减少2,3,4- 即首项为2公差为1的等差数列; 先让n减去m+1 然后让这个数列的和大于等于剩下…
当m>=n时,显然答案是n: 若m<n,在第m天之后,每天粮仓减少的量会形成等差数列,只需要二分到底在第几天,粮仓第一次下降到0即可. 若直接解不等式,可能会有误差,需要在答案旁边扫一下. 注意二分上界的确定,不能太小也不能太大. #include<cstdio> #include<iostream> using namespace std; typedef long long ll; ll n,m; int main(){ cin>>n>>m;…
链接 [https://codeforces.com/contest/785/problem/C] 题意 初始时有n,第1天先加m开始吃1,但总的不能超过n,第i天先加m开始吃i(如果不够或刚好就吃完,结束了), 问能吃多少天 分析 这个样例,模拟该过程发现规律 如果n<=m,就是n天 否则发现第m+1天比m天剩余的少1,第m+2天比m+1天剩余少2.... 就直接二分搞了 代码 #include<bits/stdc++.h> using namespace std; #define l…
Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare npotions. Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two typ…
\(数学题,式子并不难推,但边界是真的烦\) \(\color{Red}{Ⅰ.其实可以发现,当m>=n时,每次都可以粮食补到n,所以一定是在第n天消耗完毕}\) \(\color{Purple}{Ⅱ.当n>m时,前m天每次粮食都补到n}\) \(设从m+1天开始,需要mid天消耗完毕\) \(因为每天都可以加m粮食,所以mid天可以加X_{补充}=(mid-1)*m粮食(因为第m+1天是补满前一天的,所以是mid-1)\) \(然后麻雀带走的粮食用等差数列计算m+1,m+2,...,m+mid…
1343. Fairy Tale Time limit: 1.0 secondMemory limit: 64 MB 12 months to sing and dance in a ring their celestial dance. One after another they hold a throne. The first is young and fierce January and the last is elderly and wise December. Leaving the…
题目链接:http://codeforces.com/contest/734/problem/C C. Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Anton is playing a very interesting computer game, but now he i…