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: ...
随机推荐
- Jquery 提示还可以输入的字数,将多余的字数截取掉
js代码: $(function () { var counter = $("#divform textarea").val().length; //获取文本域的字符串长度 $( ...
- net 页面跳转
前台: < a href="xx.html" target="_blank"> 后台: Response.Redirect("XXX.as ...
- web前端开发学习:jQuery的原型中的init
web前端开发学习:jQuery的原型中的init 有大量web前端开发工具及学习资料,可以搜群[ web前端学习部落22群 ]进行下载,遇到学习问题也可以问群内专家以及课程老师哟 jQuery.fn ...
- Roadblocks(poj 3255)
题意:给出n个点,m条双向边,求严格次短路. /* 先spfa预处理出起点到每个点的和每个点到终点的最短距离,然后枚举每条边(这条边必须走),计算此时的最短路径,得出严格次短路. 正确性:因为对于一条 ...
- 模拟赛1029d1
第二题[题目描述]给你两个日期,问这两个日期差了多少毫秒.[输入格式]两行,每行一个日期,日期格式保证为"YYYY-MM-DD hh:mm:ss"这种形式.第二个日期时间一定比第一 ...
- Swift - 状态栏颜色显示(字体、背景)
ios上状态栏 就是指的最上面的20像素高的部分 状态栏分前后两部分,要分清这两个概念,后面会用到: 前景部分:就是指的显示电池.时间等部分: 背景部分:就是显示黑色或者图片的背景部分: 如下图:前景 ...
- NYOJ题目874签到
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAswAAAIzCAIAAACbd9iBAAAgAElEQVR4nO3dPXLjSNou0G8T8rUQ2V
- VCC、VDD、VSS、 VEE 和VPP的区别
在电子电路中,常可以看到VCC.VDD和VSS三种不同的符号,它们有什么区别呢? 一.解释 VCC:C=circuit 表示电路的意思, 即接入电路的电压: VDD:D=device 表示器件的意思, ...
- Delphi编译dll时出错"Cannot debug project unless a host application is defined.use the run|parameters...dialog box."
问题: 在编写DLL程序的时候,按下F9或者按下那个绿色的箭头,会报错,如下 原因: 是因为你按下的F9或者那个绿色箭头是表示“Run”这个程序,但是DLL不是可执行文件,所以当然不能够运行,所以就会 ...
- Extjs ComboBox 动态选中第一项
有时候我们希望通过Store加载过来的数据,ComboBoxItem能够选择第一条数据作为默认数据,我们可以这么操作: var storeinfo = Ext.create('Ext.data.Sto ...