数学 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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. hdu5634 BestCoder Round #73 (div.1)

    Rikka with Phi  Accepts: 5  Submissions: 66  Time Limit: 16000/8000 MS (Java/Others)  Memory Limit: ...

  4. (BestCoder Round #64 (div.2))Array

    BestCoder Round #64 (div.2) Array 问题描述 Vicky是个热爱数学的魔法师,拥有复制创造的能力. 一开始他拥有一个数列{1}.每过一天,他将他当天的数列复制一遍,放在 ...

  5. 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 ( ...

  6. 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 ...

  7. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  8. hdu5635 BestCoder Round #74 (div.2)

    LCP Array  Accepts: 131  Submissions: 1352  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 13 ...

  9. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

随机推荐

  1. iOS开发中调试小技巧

    对于软件开发而言,调试是必须学会的技能,重要性不言而喻.对于调试的技能,基本上是可以迁移的,也就是说你以前在其他平台上掌握的很多调试技巧,很多也是可以用在iOS开发中.不同语言.不同IDE.不同平台的 ...

  2. Swift - 开源框架总结

    苹果官方Swift文档<The Swift Programming Language> 苹果开发者Swift文档及介绍 网友整理的Swift中文文档< Apple Swift编程语言 ...

  3. java 小数点处理

    public class Test { public static void main(String[] args) { double i = 3.856; // 舍掉小数取整 System.out. ...

  4. IE6中使用通用选择器模拟子选择器效果

    IE6及更低版本不支持高级选择器:IE7有个bug,对于子选择器和相邻同胞选择器,如果父元素和子元素有HTML注释,会出问题. 下面我们使用通用选择器来模拟子选择器的效果. 原理:首先在所有后代上应用 ...

  5. haproxy 安装 各个参数的测试

    ---------------------------------------------------------------------------------------------------- ...

  6. AngularJS 之 Factory、Service、Provider

    当你初试 Angular 时,很自然地就会往 controller 和 scope 里堆满不必要的逻辑.一定要早点意识到,controller 这一层应该很薄:也就是说,应用里大部分的业务逻辑和持久化 ...

  7. T-SQL 常用语句

    1. 查看 Table 或者 Column 被那些object(存储过程.函数或View)调用. select a.* from sysobjects a, syscomments b where a ...

  8. html5 三角形

    html5 三角形 <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...

  9. memcache(使用php操作memcache)

    .概念 memcache 是一个高效的分布式的内存对象缓存系统,他可以支持把php的各种数据(数组,对象,基本数据类型)放在它管理的内存中 . 安装步骤 1.下载php_memcache.dll文件并 ...

  10. PL/SQL Developer 9.x 注册码

    记下来,以备以后使用,好笔头,哈哈哈 Product Code:46jw8l8ymfmp2twwbuur8j9gv978m2q2du serial Number:307254 password:xs3 ...