BestCoder Round #78 (div.2)
因为rating不够QAQ就报了Div2。。
[CA Loves Stick]
CA喜欢玩木棍。
有一天他获得了四根木棍,他想知道用这些木棍能不能拼成一个四边形。
2
1 1 1 1
1 1 9 2
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)的更多相关文章
- 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: ...
- hdu5634 BestCoder Round #73 (div.1)
Rikka with Phi Accepts: 5 Submissions: 66 Time Limit: 16000/8000 MS (Java/Others) Memory Limit: ...
- hdu5631 BestCoder Round #73 (div.2)
Rikka with Graph Accepts: 123 Submissions: 525 Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- hdu5630 BestCoder Round #73 (div.2)
Rikka with Chess Accepts: 393 Submissions: 548 Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- (BestCoder Round #64 (div.2))Array
BestCoder Round #64 (div.2) Array 问题描述 Vicky是个热爱数学的魔法师,拥有复制创造的能力. 一开始他拥有一个数列{1}.每过一天,他将他当天的数列复制一遍,放在 ...
随机推荐
- nyoj 8
http://acm.nyist.net/JudgeOnline/problem.php?pid=8 #include<stdio.h> #include<iostream> ...
- 基于贪心算法的几类区间覆盖问题 nyoj 12喷水装置(二) nyoj 14会场安排问题
1)区间完全覆盖问题 问题描述:给定一个长度为m的区间,再给出n条线段的起点和终点(注意这里是闭区间),求最少使用多少条线段可以将整个区间完全覆盖 样例: 区间长度8,可选的覆盖线段[2,6],[1, ...
- BZOJ 3540 realtime-update 解题
分析一下题意,大约是给定一串牛,然后找到一个跨越距离最长的牛子串使得在这个范围内白牛和花牛一样多. 白牛可以任意涂成花牛. 既然"白牛可以任意涂成花牛",那么我们需要找到一个最长的 ...
- Linux的Cgroup<实例详解>
为什么要有cgroup Linux系统中经常有个需求就是希望能限制某个或者某些进程的分配资源.也就是能完成一组容器的概念,在这个容器中,有分配好的特定比例的cpu时间,IO时间,可用内存大小等.于是就 ...
- Java锁之自旋锁详解
锁作为并发共享数据,保证一致性的工具,在JAVA平台有多种实现(如 synchronized 和 ReentrantLock等等 ) .这些已经写好提供的锁为我们开发提供了便利,但是锁的具体性质以及类 ...
- C#中Const和Readonly的区别
const 的概念就是一个包含不能修改的值的变量.常数表达式是在编译时可被完全计算的表达式.因此不能从一个变量中提取的值来初始化常量.如果 const int a = b+1;b是一个变量,显然不能再 ...
- HTML控件ID和NAME属性及在CS页面获得.ASPX页面中HTML控件的值
<转载>来自网络 一.ID是在客户端脚本里用!NAME是用于获取提交表单的某表单域信息,在form里面,如果不指定Name的话,就不会发送到服务器端,所以有name属性的控件,必须指定na ...
- iOS7 中的JavaScriptCore简单介绍
以前写过一篇介绍如何使用第三方库在ios上进行js和oc交互调用的文章,链接如下 iOS 使用UIWebView把oc代码和javascript相关联.当时建立项目时,仍然是ios6时代,所以没有原生 ...
- 【USACO】milk3
倒牛奶的问题, 开始看感觉跟倒水的问题很像, 想直接找规律, 写个类似于循环取余的代码. 但后来发现不行,因为这道题有三个桶,水量也是有限制的.只好用模拟的方法把所有的情况都试一遍. 建一个state ...
- UVA 11827 Maximum GCD (输入流)
题目:传送门 题意:求n个数的最大公约数,暴力不会超时,难点在没有个数控制的输入. 题解:用特殊方法输入. #include <iostream> #include <cmath&g ...