https://vjudge.net/problem/Gym-100283F 题意: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 .... 给出这样的序列,然后给出一个n,计算从1+1+2+1+1+2+3...加到大于等于n至少需要多少个数. 思路: 二分法. 每一行的总和为,所以第i行之前的数总和为,所以我们可以可以利用二分法,确定第i行(第i+1行的总和大于了n).接下来我们继续在第i+1行进行二分. #include<iostream> #include<alg…
数学公式: n^2的前n项和n(n+1)(2*n+1)/6,用二分进行查找: 算出层数后继续二分查找位于这一层的哪一位,也可以推出相应公式 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ll f(ll n) //a(n)=n^2的前n项和公式 { return n*…
题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds memory limit per test 256 megabytes input army.in output standard output Bakkar is now a senior college student studying computer science. And as many…
http://codeforces.com/gym/100283/problem/F 思路是二分第几行,二分出来的行是总和 >= n的,那么第k - 1行一定要选,那么再在第k行中二分那一列. #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <assert.h> #defi…
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consisting only of parentheses '(' and ')' is called balanced if it is one of the following. • A string "()" is balanced. • Concatenation of two balance…
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description It was a beautiful night at Yekaterinburg, the sky was crystal clear with no clouds, and the view of the moon and the stars was…
<题目链接> 题目大意:给你一个由01组成的矩形,现在问你,该矩形中,最多只含一个1的正方形的边长最长是多少. 解题分析: 用二维前缀和维护一下矩形的01值,便于后面直接$O(1)$查询任意子矩阵中1的个数,然后就是二分答案枚举边长. #include <bits/stdc++.h> using namespace std; template<typename T> inline void read(T&x){ x=;;char ch = getchar();…
J. Killing everything time limit per test 4 seconds memory limit per test 64 megabytes input standard input output standard output There are many enemies in the world such as red coders and hackers. You are trying eliminate everybody. Everybody is st…
题意:有N个学生和N个老师,每个人都有自己的坐标X,Y,给每个学生匹配一个老师,要求N个匹配中的距离最大值最小.其中距离的定义为:|X − X’| + |Y − Y ‘|. 分析:一道典型的最大值最小化的题目,可以二分逼近的方法找到最小值.二分中的check操作就用匈牙利匹配来判断.在匹配的过程中加入对边长的判断,或者直接根据边长限制建立新图.最后得到的上界就是答案. #include<bits/stdc++.h> using namespace std; typedef long long…
要点 非要先来后到暗示多源最短路,求最小的最大值暗示二分 二分内部的check是关键,dp处理一下,\(dp[i]\)表示第\(i\)笔订单最早何时送达,如果在ddl之前到不了则\(return\ 0\).我觉得其中\(time\)变量的维护很好地使复杂度降了一维. 第一发WA点:算法看了一遍感觉没有可改的,就把二分的\(r\)调大了,又把\(longlong\)的输入输出改为流,莽试一发就过了-- #include <cstdio> #include <iostream> #in…