因为rating不够QAQ就报了Div2。。

[CA Loves Stick]

CA喜欢玩木棍。
有一天他获得了四根木棍,他想知道用这些木棍能不能拼成一个四边形。
Sample Input
2
1 1 1 1
1 1 9 2
Sample Output
Yes
No

CE的心塞啊。。居然没有<bits/stdc++.h>

#include <cstdio>
#include <algorithm>
#include <iostream> using namespace std; typedef unsigned long long ll;
ll a[4];
int main(){
int test;
scanf("%d", &test);
while(test --){
for(int i = 0; i < 4; i ++)
cin >> a[i];
sort(a, a+4);
bool flag = true;
for(int i = 0; i < 4; i ++)
if(a[i] == 0){
flag = false;
break;
}
if(flag == false || a[3] - a[2] >= a[0] + a[1])
puts("No");
else puts("Yes");
}
return 0;
}

[CA Loves GCD]

问题描述
CA喜欢是一个热爱党和人民的优秀同♂志,所以他也非常喜欢GCD(请在输入法中输入GCD得到CA喜欢GCD的原因)。
现在他有N个不同的数,每次他会从中选出若干个(至少一个数),求出所有数的GCD然后放回去。
为了使自己不会无聊,CA会把每种不同的选法都选一遍,CA想知道他得到的所有GCD的和是多少。
我们认为两种选法不同,当且仅当有一个数在其中一种选法中被选中了,而在另外一种选法中没有被选中。
输入样例
2
2
2 4
3
1 2 3
输出样例
8
10

枚举因子,容斥,还是蛮简单的。。(也不知道是谁调了很久都没调出来)

可以做到O(nlogn).然而手残写的O(n^2)

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#define maxn 1010
using namespace std;
typedef long long ll;
#define mod 100000007 int a[maxn], n; ll ans[maxn], pow2[maxn]; int main(){
int test;
scanf("%d", &test);
pow2[0] = 1;
for(int i = 1; i <= 1000; i ++)
pow2[i] = (pow2[i-1] << 1) % mod;
while(test --){
scanf("%d", &n);
int mx = 0;
for(int i = 1; i <= n; i ++)
scanf("%d", &a[i]), mx = max(mx, a[i]);
sort(a+1, a+1+n);
memset(ans, 0, sizeof ans);
for(int i = 1; i <= mx; i ++){
int cnt = 0;
for(int j = 1; j <= n; j ++)
cnt += a[j] % i == 0;
ans[i] = pow2[cnt] - 1;
} for(int i = mx; i; i --)
for(int j = i + i; j <= mx; j += i)
ans[i] -= ans[j], ans[i] %= mod; ll ret = 0;
for(int i = 1; i <= mx; i ++)
ret += 1ll * ans[i] * i, ret %= mod; printf("%I64d\n", (ret + mod) % mod);
}
return 0;
}
[CA Loves Palindromic]
CA喜欢字符串,尤其喜欢回文串。
有一天他得到一个字符串,他想知道子串中有多少回文子串,本质相同位置不同的算一种。每次给个区间[l, r]

然后就是PAM。。枚举l暴力构建PAM。。

因为len<=1000还蛮小的QAQ

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#define maxn 2010
using namespace std; int n, s[maxn]; char str[maxn]; struct Node{
int fail, nxt[26], len;
void clear(){
memset(nxt, 0, sizeof nxt);
len = fail = 0;
}
}st[maxn]; int last, size, len; void init(){
last = len = 0;
st[0].clear(), st[1].clear();
st[0].len = 0, st[1].len = -1;
st[0].fail = st[1].fail = 1;
s[0] = -1; size = 1;
} int get_fail(int x){
while(s[len-st[x].len-1] != s[len])
x = st[x].fail;
return x;
} int sz[maxn]; void Extend(int c){
s[++ len] = c;
int cur = get_fail(last);
if(!st[cur].nxt[c]){
int now = ++ size;st[now].clear();
st[now].len = st[cur].len + 2;
st[now].fail = st[get_fail(st[cur].fail)].nxt[c];
st[cur].nxt[c] = now;
}
last = st[cur].nxt[c];
} int ans[maxn][maxn]; void solve(){
for(int i = 1; i <= n; i ++){
init();
for(int j = i; j <= n; j ++){
Extend(str[j]-'a');
ans[i][j] = size - 1;
}
}
} void read(int& num){
char ch = getchar(); num = 0;
for(; ch < '!'; ch = getchar());
for(; ch > '!'; ch = getchar())
num = (num << 1) + (num << 3) + (ch ^ 48);
} int main(){
int test;
scanf("%d", &test);
while(test --){
init();
scanf("%s", str+1);
n = strlen(str+1);
solve();
int Q, l, r;
read(Q);
for(int i = 1; i <= Q; i ++){
read(l), read(r);
printf("%d\n", ans[l][r]);
}
} return 0;
}

  

  

BestCoder Round #78 (div.2)的更多相关文章

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

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

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

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

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

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

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

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

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

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

  7. hdu5631 BestCoder Round #73 (div.2)

    Rikka with Graph  Accepts: 123  Submissions: 525  Time Limit: 2000/1000 MS (Java/Others)  Memory Lim ...

  8. hdu5630 BestCoder Round #73 (div.2)

    Rikka with Chess  Accepts: 393  Submissions: 548  Time Limit: 2000/1000 MS (Java/Others)  Memory Lim ...

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

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

随机推荐

  1. HDOJ 1596

    9899828 2013-12-27 16:42:37 Accepted 1596 3312MS 6668K 711 B C++ 泽泽 floyed暴力 #include<cstdio> ...

  2. python __init__ __call__

    __call__ 和 __init__半毛钱的关系都没有. 后者是构造类的实例时会调用的方法,并不是构造方法. 前者是在实例上可以呼叫的方法.代码示例如下: >>> class fo ...

  3. Python获取目录、文件的注意事项

    Python获取指定路径下的子目录和文件有两种方法: os.listdir(dir)和os.walk(dir),前者列出dir目录下的所有直接子目录和文件的名称(均不包含完整路径),如 >> ...

  4. 交换排序—冒泡排序(Bubble Sort)

    基本思想: 在要排序的一组数中,对当前还未排好序的范围内的全部数,自上而下对相邻的两个数依次进行比较和调整,让较大的数往下沉,较小的往上冒. 即:每当两相邻的数比较后发现它们的排序与排序要求相反时,就 ...

  5. Android Studio项目整合PullToRefresh的问题记录

    PullToRefresh下拉刷新在App中应用非常频繁,然而PullToRefresh是在ADT下开发完成的.如果要将其整合到Android Studio目录下的话颇费周折.前面的文章“Androi ...

  6. MySQL自带information_schema数据库使用

    MySQL的information_schema数据库是什么,有什么作用? 大家在安装或使用MYSQL时,会发现除了自己安装的数据库以外,还有一个 information_schema数据库.info ...

  7. iOS 如何使用自定义字体

    首先,你需要有字体文件,比如 xxx.otf,之后你需要到工程的info配置文件中加入Fonts provided by application的值,如下图 之后,就可以使用字体名和UIFont的方法 ...

  8. iOS 和Android中的基本日期处理

    提到日期处理,主要有2个参数,一个是所在的时区,一个是所用的日历方法. 主要涉及2大类问题,一类是日期类型和字符串之间的转化,另一类是日期的计算问题.ios和android都提供了相应的类来处理问题. ...

  9. stm32学习笔记——外部中断的使用

    stm32学习笔记——外部中断的使用 基本概念 stm32中,每一个GPIO都可以触发一个外部中断,但是,GPIO的中断是以组为一个单位的,同组间的外部中断同一时间只能使用一个.比如说,PA0,PB0 ...

  10. 微信api退款操作

    状况:证书加载进去,本地调试退款成功,然而发不到iis上却是不成功. 分析:定然是iis配置问题. 问题一:证书加载不进去,出现“内部错误” 解决:在iis中找到对应的应用连接池,右键高级设置,找到“ ...