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: ...
随机推荐
- java Http原生 Get 和Post 支持代理认证
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import ...
- Android 录音
想要实现wav格式的编码时我们也就不能再使用MediaRecorder,而只能使用AudioRecord进行处理
- poj1417(种类并查集+dp)
题目:http://poj.org/problem?id=1417 题意:输入三个数m, p, q 分别表示接下来的输入行数,天使数目,恶魔数目: 接下来m行输入形如x, y, ch,ch为yes表示 ...
- 无废话Android之smartimageview使用、android多线程下载、显式意图激活另外一个activity,检查网络是否可用定位到网络的位置、隐式意图激活另外一个activity、隐式意图的配置,自定义隐式意图、在不同activity之间数据传递(5)
1.smartimageview使用 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...
- Delphi的字符串、PChar和字符数组之间的转换
参考:http://my.oschina.net/kavensu/blog/193719 以下的各种方法都是我在Delphi 6的环境下测试成功的,可能根据你的开发环境.不同的上下文语境……有一些可能 ...
- Python 的三目运算
其他语言:php 判定条件?为真时的结果:为假时的结果 $a=88 $b=99 $res = $a>$b?$a>$b 搞笑的Python:令人意想不到的语法形式 true_value if ...
- 【JAVA多线程安全问题解析】
一.问题的提出 以买票系统为例: class Ticket implements Runnable { public int sum=10; public void run() { while(tru ...
- BI 项目管理之生命周期跟踪和任务区域
DW/BI 系统是复杂的实体,构建这种系统的方法必须有助于简化复杂性.13 个方框显示了构建成功的数据仓库的主要任务区域,以及这些任务之间的主要依赖关系. 在生命周期这一级可以进行多方观察 ...
- subversion安装使用
这里仅针对subversion进行说明,未完待续. 一.下载subversion并安装: a.subversion 要做svn服务器的必须装 b.Tortoisesvn 仅仅是访问svn服务器的客户端 ...
- C# Qrcode生成二维码支持中文,带图片,带文字 2015-01-22 15:11 616人阅读 评论(1) 收藏
1.下载Qrcode库源码,下载地址:http://www.codeproject.com/Articles/20574/Open-Source-QRCode-Library 2.打开源码时,部分类库 ...