因为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 100000007int 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;
}

  

  

转载于:https://www.cnblogs.com/Candyouth/p/5348321.html

BestCoder Round #78 (div.2)相关推荐

  1. BestCoder Round #78 (div.2)_B_ CA Loves GCD

    CA Loves GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) T ...

  2. HDU 5597 GTW likes function(规律+欧拉函数模板题)——BestCoder Round #66(div.1 div.2)

    GTW likes function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth ...

  3. BC div2补题以及 复习模除 逆元__BestCoder Round #78 (div.2)

    第一题没话说 智商欠费 加老柴辅导终于过了 需要在意的是数据范围为2的63次方-1 三个数相加肯定爆了 四边形的定义 任意边小于其余三边之和 换句话说就是 最长边小于其余三边之和 这样的话问题转化为 ...

  4. (BestCoder Round #59 (div.1) B)简单DP

    (改编版,题意相同) Description 火神为了检验zone的力量,他决定单挑n个人. 由于火神训练时间有限,最多只有t分钟,所以他可以选择一部分人来单挑,由于有丽子的帮助,他得到了每个人特定的 ...

  5. BestCoder Round #68 (div.2) 1002 tree

    题意:给你一个图,每条边权值0或1,问每个点周围最近的点有多少个? 思路:并查集找权值为0的点构成的连通块. 1 #include<stdio.h> 2 #include<strin ...

  6. ACM学习历程—HDU5586 Sum(动态规划)(BestCoder Round #64 (div.2) 1002)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 题目大意就是把一段序列里面的数替换成f(x),然后让总和最大. 首先可以计算出初始的总和,以及每 ...

  7. BestCoder Round #67 (div.2) 1001——N bulbs

    题意:给定一个长度为n的灯泡的状态序列,经过每个灯泡时,都要开关一下(开变关,关变开),问能否在回到终点的条件下关掉所有的灯. 思路:没出现一个为1的灯,都需要走奇数步来关掉它,而灯的总数为奇数的时候 ...

  8. BestCoder Round #66 (div.2) 1002

    GTW likes gt  Accepts: 132  Submissions: 772  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

  9. BestCoder Round #77 (div.2)解题报告

    昨晚和Yveh合作的成果-- T1 传送门 题意:给一个正整数集合,求集合中各个子集里各元素的总异或 思路:对于一个数x对自己异或的结果,异或偶数次是x,奇数次为0,而且一个集合的非空子集数目为2n− ...

最新文章

  1. Logstash(二)input、codec插件详解
  2. 独家 | 请停止使用浏览器过程中的不安全行为(附链接)
  3. FAQ系列 | 监控平均SQL响应时长
  4. 对话高博(一)| 机器码、Pascal,以及计算机学习的分形
  5. java专业日报800字,JAVA每日学习日报 7.8
  6. ITK:侵蚀灰度图像
  7. NHibernate介绍
  8. spring boot 与redis 整合
  9. 电商标识检测的鲁棒性防御,ACM MM2021 安全AI大赛技术解析
  10. 获取字段_数据库中敏感字段的标记、标示
  11. Python自动化办公 | 补写178份Word日报!
  12. 作用域和请求参数传递
  13. HTML5权威指南pdf
  14. QImage互转cv::Mat
  15. 把Excel里的折线图另存为图片
  16. 【寒江雪】Go实现Builder Pattern
  17. 携程网创始人季琦:互联网已不再有机会(转)
  18. 植物大战僵尸 - 修改关卡和商店金钱
  19. nginxWebUI :nginx可视化配置工具---实践
  20. html5-canvas常用的api介绍

热门文章

  1. python生成条形图-Python处理JSON数据并生成条形图
  2. python下载安装包-python安装包 官方版
  3. python基础教程教材-Python3零基础教材电子书合集
  4. python必背100代码-这 100 道 Python 题,拿去刷!!!
  5. python发明者叫什么-编程语言简史:有人不喜欢花括号,于是他发明了 Python
  6. python教程第四版pdf下载-Python参考手册 第4版高清中文PDF下载
  7. python考级证书-python二级证书有用吗
  8. python处理excel大数据-当Excel遇到大数据问题,是时候用Python来拯救了
  9. python教程txt免费下载-python编程从入门到实践PDF电子书教程免费下载
  10. python常用函数-python常用函数与用法示例