A - Codehorses T-shirts

思路:有相同抵消,没有相同的对答案+1

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = 1e5 + ;
const int M = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; string a[], b[];
int n; map<string, int> mp;
int main(){
scanf("%d", &n);
for(int i = ; i <= n; i++) cin >> a[i], mp[a[i]]++;
int ans = ;
for(int i = ; i <= n; i++) {
cin >> b[i];
if(mp[b[i]]) {
mp[b[i]]--;
} else {
ans++;
}
}
printf("%d\n", ans);
return ;
} /*
*/

B - Light It Up

思路:求一下前缀,如果要加一个开关肯定是加在原来是关的前面一个或者后面一个,枚举一下就好啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ; int n, M, sum[N], fsum[N], a[N];
int main(){
scanf("%d%d", &n, &M);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
a[++n] = M;
for(int i = ; i <= n; i++) {
sum[i] = sum[i - ];
if(i & ) sum[i] += a[i] - a[i - ];
fsum[i] = a[i] - sum[i];
} int ans = sum[n];
for(int i = ; i < n; i++) {
if(i & ) {
if(a[i] > a[i - ] + ) {
int ret = a[i] - a[i - ] - ;
ret += fsum[n] - fsum[i];
ret += sum[i - ];
ans = max(ans, ret);
} if(a[i] < a[i + ] - ) {
int ret = sum[i];
ret += fsum[n] - fsum[i + ];
ret += a[i + ] - a[i] - ;
ans = max(ans, ret);
}
}
} printf("%d\n", ans);
return ;
} /*
*/

C - Covered Points Count

思路:离散化差分标记搞一搞

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = 1e6 + + 2e5;
const int M = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; LL n, tot, in[N], out[N], ans[N];
LL hs[N], l[N], r[N]; int main(){
scanf("%lld", &n);
for(int i = ; i <= n; i++) {
scanf("%lld%lld", &l[i], &r[i]);
hs[++tot] = l[i];
hs[++tot] = r[i];
hs[++tot] = l[i] + ;
hs[++tot] = l[i] - ;
hs[++tot] = r[i] + ;
hs[++tot] = r[i] - ;
} sort(hs + , hs + + tot);
tot = unique(hs + , hs + + tot) - hs - ; for(int i = ; i <= n; i++) {
int pos1 = lower_bound(hs + , hs + + tot, l[i]) - hs;
int pos2 = lower_bound(hs + , hs + + tot, r[i]) - hs;
in[pos1]++;
out[pos2]++;
} LL cnt = ;
for(int i = ; i < tot; i++) {
cnt += in[i];
ans[cnt]++;
cnt -= out[i];
LL num = hs[i + ] - hs[i] - ;
ans[cnt] += num;
} cnt += in[tot];
ans[cnt]++; for(int i = ; i <= n; i++) printf("%lld ", ans[i]);
return ;
} /*
*/

D - Yet Another Problem On a Subsequence

题目大意:给你n个数字 (n <= 1000), 问你有多少个子序列是good  sequence

good sequence的定义是能变成若干个good arrays

good array 的定义是这个数组的第一个元素的值等于这个数组的length - 1。

思路: A了三题之后日常开始挂机。。。 还是太菜啦!!!!

比赛的时候感觉是个dp,但是不知到如何定义状态。。。

后来发现原来我看错了题,原来是把good sequence划分成若干个good arrays

我们定义dp[ i ],表示从第 i 个开始,并且 i 作为一个array第一个元素的的合法答案的方案数。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = 1e3 + ;
const int M = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ; int a[N], dp[N], C[N][N], n; void init() {
for(int i = (C[][] = ); i < N; i++)
for(int j = (C[i][] = ); j < N; j++)
C[i][j] = (C[i - ][j] + C[i - ][j - ]) % mod;
} int main() {
init();
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d", &a[i]);
} dp[n + ] = ; for(int i = n; i >= ; i--) {
if(a[i] > ) {
for(int j = i + a[i] + ; j <= n + ; j++) {
dp[i] = (dp[i] + 1LL * dp[j] * C[j - i - ][a[i]]) % mod;
}
}
} int ans = ; for(int i = ; i <= n; i++) {
ans = (ans + dp[i]) % mod;
} printf("%d\n", ans);
return ;
}
/*
*/

Educational Codeforces Round 46 (Rated for Div. 2)的更多相关文章

  1. Educational Codeforces Round 46 (Rated for Div. 2) E. We Need More Bosses

    Bryce1010模板 http://codeforces.com/contest/1000/problem/E 题意: 给一个无向图,求图的最长直径. 思路:对无向图缩点以后,求图的最长直径 #in ...

  2. Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/C 题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...

  3. Educational Codeforces Round 46 (Rated for Div. 2) B. Light It Up

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/B 思路:先用两个数组sumon[]和sumoff[]将亮着的灯和灭的灯累计一下. ...

  4. Educational Codeforces Round 46 (Rated for Div. 2) A. Codehorses T-shirts

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/A 题意: 问你将一种类型的衣服转换成另一种的最小次数. #include<b ...

  5. Educational Codeforces Round 46 (Rated for Div. 2) D. Yet Another Problem On a Subsequence

    这个题是dp, dp[i]代表以i开始的符合要求的字符串数 j是我们列举出的i之后一个字符串的开始地址,这里的C是组合数 dp[i] += C(j - i - 1, A[i]] )* dp[j]; # ...

  6. Educational Codeforces Round 46 (Rated for Div. 2) D

    dp[i]表示一定包含第I个点的好的子序列个数,那么最终答案就是求dp[0] + dp[1] + .... + dp[n-1] 最终的子序列被分成了很多块,因此很明显我们枚举第一块,第一块和剩下的再去 ...

  7. Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序

    Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] ​ 给你 ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

随机推荐

  1. mysql 如何解决字段不区分大小写的问题

    当我们输入不管大小写都能查询到数据,例如:输入 aaa 或者aaA ,AAA都能查询同样的结果,说明查询条件对大小写不敏感. 解决方案一: 于是怀疑Mysql的问题.做个实验:直接使用客户端用sql查 ...

  2. windows中apache+tomcat整合,使php和java项目能够独立运行

    一.下载和安装 1.安装php  网上有安装教程,不再赘述 2.安装apache 比如安装目录为e:\apache;  项目根目录为e:\www;   网上有安装教程,不再赘述 3.安装jdk  不再 ...

  3. JavaSE的学习路线

    基于现阶段的JavaEE学习的对象,主要是趋向于Web的方向,主要就是说在JavaWeb的基础上进行进一步的开发和学习,下面我会将自己总结的对于自己的一点关于JavaEE学习路线会逐步讲解. 第一部分 ...

  4. 2015年IPC网络摄像机技术发展现状分析

    网络摄像机将图像转换为基于TCP/IP网络标准的数据包,使摄像机所摄的画面通过RJ-45以太网接口或WIFI WLAN无线接口直接传送到网络上,通过网络即可远端监视画面. 一.网络摄像机的基本原理 网 ...

  5. Spring 与 SpringMVC 容器父子关系引出的相应问题

    1)关系说明 spring 与 springmvc 父子关系:spring (父容器),springmvc (子容器) springmvc(子)--- 可调用 --> spring(父) 中的 ...

  6. 根据wsdl的url,使用axis1.4生成客户端,并且对webservice进行调用(转)

    根据wsdl的url,使用axis1.4生成客户端,并且对webservice进行调用 axis1.4下载地址 1.到www.apache.org上去下载axis-bin-1_4.zip,如要关联源代 ...

  7. spring boot 2.0.3+spring cloud (Finchley)7、服务链路追踪Spring Cloud Sleuth

    参考:Spring Cloud(十二):分布式链路跟踪 Sleuth 与 Zipkin[Finchley 版] Spring Cloud Sleuth 是Spring Cloud的一个组件,主要功能是 ...

  8. 重构改善既有代码设计--重构手法02:Inline Method (内联函数)& 03: Inline Temp(内联临时变量)

    Inline Method (内联函数) 一个函数调用的本体与名称同样清楚易懂.在函数调用点插入函数体,然后移除该函数. int GetRating() { return MoreThanfiveLa ...

  9. 设置display:inline-block产生间隙

    display:inline-block产生间隙,是由于换行在内的空白符 display:inline-block在IE下仅仅是触发了layout,而它本是行布局,触发后,块元素依然还是行布局.所以需 ...

  10. 2017ACM暑期多校联合训练 - Team 1 1006 HDU 6038 Function (排列组合)

    题目链接 Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m ...