BestCoder Round #71 (div.2)
数学 1001 KK's Steel
类似斐波那契求和
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue> typedef long long ll;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7; ll run(ll n) {
ll a = 1, b = 2, c;
ll sum = 3, ret = 2;
while (sum < n) {
c = a + b;
if (sum + c < n) {
sum += c;
a = b; b = c;
ret++;
}
if (sum + c > n) return ret;
if (sum + c == n) return ret + 1;
}
return ret;
} int main(void) {
int T; scanf ("%d", &T);
while (T--) {
ll n; scanf ("%I64d", &n);
if (n <= 2) puts ("1");
else {
ll ans = run (n);
printf ("%I64d\n", ans);
}
} return 0;
}
数学 1002 KK's Point
圆上四个点连线能成圆内一个点,所以答案就是comb (n, 4) + n
#include <cstdio>
int main(void) {
int T; scanf ("%d", &T);
while (T--) {
int n; scanf ("%d", &n);
if (n < 4) printf ("%d\n", n);
else {
unsigned long long ans = 1;
ans = ans * n * (n - 1) / 2 * (n - 2) / 3 * (n - 3) / 4 + n;
printf ("%I64d\n", ans);
}
}
return 0;
}
还有自己想出来的结论
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue> typedef long long ll;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7; ll fun(int x) {
return 1ll * (1 + x) * x / 2;
} int main(void) {
int T; scanf ("%d", &T);
while (T--) {
int n; scanf ("%d", &n);
ll ans = n;
n -= 3;
int t = 1;
while (n >= 1) {
ans += fun (n) * t;
n--; t++;
}
printf ("%I64d\n", ans);
} return 0;
}
DP 1004 KK's Number
显然,每个人的策略就是都会拿剩下的数中最大的某几个数
假如我们用f[i]表示当剩下i个数的时候先手得分-后手得分的最小值
那么得到f[i]=max\left(a[j+1]-f[j] \right)(1<j\leq i)f[i]=max(a[j+1]−f[j])(1<j≤i)
但是这样做,是要超时的
我们不妨简单转换一下 f[i]=_max; _max=max(_max,a[i+1]-f[i]);
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue> typedef long long ll;
const int N = 5e4 + 5;
const int MOD = 1e9 + 7;
int a[N];
long long dp[N]; int main(void) {
int T; scanf ("%d", &T);
while (T--) {
int n; scanf ("%d", &n);
for (int i=0; i<n; ++i) scanf ("%d", &a[i]);
std::sort (a, a+n);
dp[0] = a[0];
for (int i=1; i<n; ++i) {
dp[i] = std::max (dp[i-1], a[i] - dp[i-1]);
}
printf ("%I64d\n", dp[n-1]);
} return 0;
}
BestCoder Round #71 (div.2)的更多相关文章
- BestCoder Round #71 (div.2) (hdu 5621)
KK's Point Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- BestCoder Round #71 (div.2) (hdu 5620 菲波那切数列变形)
KK's Steel Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu5634 BestCoder Round #73 (div.1)
Rikka with Phi Accepts: 5 Submissions: 66 Time Limit: 16000/8000 MS (Java/Others) Memory Limit: ...
- (BestCoder Round #64 (div.2))Array
BestCoder Round #64 (div.2) Array 问题描述 Vicky是个热爱数学的魔法师,拥有复制创造的能力. 一开始他拥有一个数列{1}.每过一天,他将他当天的数列复制一遍,放在 ...
- BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)
Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- BestCoder Round #68 (div.2) tree(hdu 5606)
tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- BestCoder Round #11 (Div. 2) 题解
HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu5635 BestCoder Round #74 (div.2)
LCP Array Accepts: 131 Submissions: 1352 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 13 ...
- hdu 5636 搜索 BestCoder Round #74 (div.2)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
随机推荐
- 多米诺(codevs 3052)
题目描述 Description 一个矩形可以划分成M*N个小正方形,其中有一些小正方形不能使用.一个多米诺骨牌占用两个相邻的小正方形.试问整个区域内最多可以不重叠地放多少个多米诺骨牌且不占用任何一个 ...
- 关于KVC、KVO
KVC/KVO --------------------KVC--键值编码-------------------作用:通过字符串来描述对象的属性间接修改对象的属性 Student *stu=[[Stu ...
- poj1703(各种姿势)
题目链接:http://poj.org/problem?id=1703 题意:有n个人分别属于两个团伙,接下来m组形如 ch, x, y的数据,ch为"D"表示 x, y属于不同的 ...
- JQ AJAX
用AJAX方法不刷新网页使用下拉列表连接数据库 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
- DedeCMS Error: (PHP 5.3 and above) Please set request_order
部分使用PHP 5.3的主机可能会有下面的提示: (PHP 5.3 and above) Please set 'request_order' ini value to include C,G and ...
- Delphi测试线程的时间
在16位时代,当我们在Windows3.x下编程时,经常会用到GetTickCount()或者timeGetTime()来判断一段代码的执行时间.示例如下 var StartTime, Total: ...
- 莫队算法 2038: [2009国家集训队]小Z的袜子(hose)
链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2038 2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 ...
- 攻城狮在路上(壹) Hibernate(十五)--- Hibernate的高级配置
一.配置数据库连接池: 1.使用默认的数据库连接池: Hibernate提供了默认了数据库连接池,它的实现类为DriverManegerConnectionProvider,如果在Hibernate的 ...
- JavaScript - UnderScore
UnderScore 第一步 call(this) (function() {}.call(this)); 一些简单的初始化操作 (function() { var root = this; var ...
- Create a Qt Widget Based Application—Windows
This turtorial describes how to use Qt Creator to create a small Qt application, Text Finder. It is ...