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: ...
随机推荐
- iOS开发MAC下配置Svn和Git
如果你对iOS开发中的版本控制还不了解那么你可以先看看这篇(大致看一遍就ok) http://www.cnblogs.com/iCocos/p/4767692.html 关于版本控制使用起来并不难 ...
- Undefined symbols for architecture x86_64: ( linker command failed with exit code 1)
当出现 linker command failed with exit code 1 (use -v to see invocation) 的错误总结,具体内容如下: Undefined symbo ...
- September 22nd 2016 Week 39th Thursday
Things won are done, the soul of joy lies in the doing. 得到即是完结,快乐的精髓在于过程. Things won are done, thing ...
- 项目差异class文件提取-->上线用
package fileReader; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStre ...
- spring整合httpclient
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://w ...
- Quartus 11.0 的AS 下载方式和JTAG下载jic文件的方式
FPGA下载的三种方式:主动配置方式(AS)和被动配置方式(PS)和最常用的(JTAG)配置方式: AS由FPGA器件引导配置操作过程,它控制着外部存储器和初始化过程,EPCS系列.如EPCS1,EP ...
- 《C#本质论》读书笔记(14)支持标准查询操作符的集合接口
14.2.集合初始化器 使用集合初始化器,程序员可以采用和数组相似的方式,在集合的实例化期间用一套初始的成员来构造这个集合. 如果没有集合初始化器,就只有在集合实例化后才能显示添加到集合中--例如 ...
- 22.访问者模式(Vistor Pattern)
using System; using System.Collections; namespace ConsoleApplication5 { /// <summary> /// 访问者模 ...
- xml解析方法总结
==========================================xml文件<?xml version=”1.0″ encoding=”GB2312″?> <RES ...
- 第六届acm省赛总结(退役贴)
前言: 这是我的退役贴,之前发到了空间里,突然想到也要在博客里发一篇,虽然我很弱,但是要离开了还是有些感触,写出来和大家分享一下,希望不要见笑.回来看看,这里也好久没有更新了,这一年确实有些懈怠,解题 ...