http://codeforces.com/contest/888

Local Extrema【水】

【题意】:计算极值点个数

【分析】:除了第一个最后一个外,遇到极值点ans++,包括极大和极小

【代码】:

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n,a[+];
  8. int maxn,minn;
  9. maxn=minn=;
  10. cin>>n;
  11. for(int i=;i<=n;i++)
  12. {
  13. cin>>a[i];
  14. }
  15. for(int i=;i<=n-;i++)
  16. {
  17. if(a[i]>a[i+]&&a[i]>a[i-]) maxn++;
  18. if(a[i]<a[i+]&&a[i]<a[i-]) minn++;
  19. }
  20. cout<<minn+maxn<<endl;
  21. return ;
  22. }

暴力

Buggy Robot【模拟】

【题意】:机器人从(0,0)出发,有UDLR四种走法,分别代表上下左右的方向,最后回到(0,0),给你一段包含这些走法的序列,求最多有几个走法正确(即可以删去最少的操作使其能够回到原点)。

【分析】:记录下四个方向执行了几次,然后取相反方向的最小值乘2。我是这么想的,还特判了。最后被hack了···

【代码】:

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n,min1,min2;
  8. int l,d,u,r;
  9. l=d=u=r=min1=min2=;
  10. char a[];
  11. cin>>n;
  12. for(int i=;i<n;i++)
  13. {
  14. cin>>a[i];
  15. if(a[i]=='L') l++;
  16. else if(a[i]=='D') d++;
  17. else if(a[i]=='U') u++;
  18. else r++;
  19. }
  20. if(l&&(!r)){
  21. printf("0\n");
  22. return ;
  23. }
  24. if(r&&(!l)){
  25. printf("0\n");
  26. return ;
  27. }
  28. if(u&&(!d)){
  29. printf("0\n");
  30. return ;
  31. }
  32. if(d&&(!u)){
  33. printf("0\n");
  34. return ;
  35. }
  36.  
  37. if(l&&r) min1=*min(l,r);
  38. if(u&&d) min2=*min(u,d);
  39.  
  40. printf("%d\n",min1+min2);
  41. return ;
  42. }

被hack代码

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. ios_base::sync_with_stdio(false);
  5. cin.tie(NULL);
  6. int N,l=,r=,u=,d=;
  7. cin>>N;
  8. string s;
  9. cin>>s;
  10. for(int i=;i<s.length();i++){
  11. if(s[i]=='L')l++;
  12. if(s[i]=='R')r++;
  13. if(s[i]=='U')u++;
  14. if(s[i]=='D')d++;
  15. }
  16. cout<<*(min(l,r)+min(u,d))<<endl;
  17. }

AC

K-Dominant Character【贪心】

【题意】:给一小写字母组成的字符串,找个长度最短的k。使得这些长度为k的子串必须包含了某同一个字符。

【分析】:记录下两个相同字符的最长距离,然后取这些距离的最小值。最小化最大值。

一个数组记录该字母上一次出现的位置

一个数组记录该字母相邻最大距离

如果没有重复出现的字符呢

设定在-1和len两个位置上和所以字母相同

 比如abbbabba串,对于字母a,有距离4,3,那么数组里存的就是4 

(金牌讲师010):对于aab
有a这个位置的是
1 2
字符串长度是3
间距分别是
0-1 1
1-2 1
2-4 2
0和4是字符串的边界外
所以对于字符a就是2是最大间距
b只有3这个位置出现
0-3 3
3-4 1
所以b的最大间距是3
这题答案就是2
字符串的边界外也算进去?
因为
___x___x____x__
两边还有__
x是出现的位置

【代码】:

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int inf = 0x3f3f3f3f;
  5. const long long INF = 0x3f3f3f3f3f3f3f3fLL;
  6. const double pi = acos(-1.0);
  7. const int maxn = +;
  8. const int mod = 1e9+;
  9. char a[maxn];
  10. int main()
  11. {
  12. //freopen("in.txt","r",stdin);
  13. //freopen("out.txt","w",stdout);
  14. int n;
  15. scanf("%s",a+);
  16. int len=strlen(a+),ans=len;
  17. for (int i=;i<;i++){
  18. int tmp=;
  19. int pos=;
  20. for (int j=;j<=len;j++)if (a[j]==i)tmp=max(tmp,j-pos),pos=j;
  21. tmp=max(tmp,len+-pos);
  22. ans=min(ans,tmp);
  23. }
  24. printf("%d\n",ans);
  25. return ;
  26. }
D. Almost Identity Permutations【排列组合】
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array.

Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that pi = i.

Your task is to count the number of almost identity permutations for given numbers n and k.

Input

The first line contains two integers n and k (4 ≤ n ≤ 1000, 1 ≤ k ≤ 4).

Output

Print the number of almost identity permutations for given n and k.

Examples
input
  1. 4 1
output
  1. 1
input
  1. 4 2
output
  1. 7
input
  1. 5 3
output
  1. 31
input
  1. 5 4
output
  1. 76
  2.  
  3. 【题意】:一个长为n的排列,其中pi=i的位置大于等于n-k的排列方案数, 比如n=5 k=3让你求有多少个1 2 3 4 5的排列使得至少5-3=2个数字在“原位”
    【分析】:公式是C(n,i)*D(i) (0<=i<=k),
错排只用弄到4,
组合数也只用弄到1000,4 
 
  1. 【代码】:
  1. By RoniKing, contest: Educational Codeforces Round , problem: (D) Almost Identity Permutations, Accepted, #
  2. #include <bits/stdc++.h>
  3. #define LL long long
  4. using namespace std;
  5. //const int mod=1e9+7;
  6. const int maxn=1e3+;
  7. LL D[maxn], C[maxn][];
  8. int p[+];
  9. void init()
  10. {
  11. D[]=;
  12. D[]=;
  13. for(int i=;i<maxn;i++)//错排
  14. D[i]=((i-)*(D[i-]+D[i-]));
  15. int i;
  16. //for (p[0]=i=1;i<=200000;i++) p[i]=1ll*p[i-1]*i%mod;
  17. for (int i = ; i < maxn; i++)//排列组合
  18. {
  19. for (int j = ; j <= min(, i); j++)
  20. {
  21. if (j == ) C[i][j] = ;
  22. else
  23. C[i][j] = (C[i-][j] + C[i-][j-]) ;
  24. }
  25. }
  26. }
  27. int main()
  28. {
  29. init();
  30. int t;
  31.  
  32. int n,k;
  33. cin>>n>>k;
  34. LL ans=;
  35. for(LL i=;i<=n;i++)
  36. ans = ans * i ;
  37. LL val=;
  38. for(int i=;i<=k;i++)
  39. val=(val + D[i]*C[n][i]) ;
  40. // cout<<ans<<endl;
  41. cout<<val<<endl;
  42. //cout<<(ans-val)<<endl;
  43.  
  44. }

我的丑代码

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. long long n,k;
  8. cin>>n>>k;
  9. long long ans=;
  10. if(k>=) ans+=n*(n-)/;
  11. if(k>=) ans+=n*(n-)*(n-)/;
  12. if(k>=) ans+=n*(n-)*(n-)*(n-)*/;
  13. cout<<ans;
  14. return ;
  15. }

简♂短

Educational Codeforces Round 32的更多相关文章

  1. Educational Codeforces Round 32 Problem 888C - K-Dominant Character

    1) Link to the problem: http://codeforces.com/contest/888/problem/C 2) Description: You are given a ...

  2. Educational Codeforces Round 32 E. Maximum Subsequence

    题目链接 题意:给你两个数n,m,和一个大小为n的数组. 让你在数组找一些数使得这些数的和模m最大. 解法:考虑 dfs但是,数据范围不允许纯暴力,那考虑一下折半搜索,一个从头开始往中间搜,一个从后往 ...

  3. Educational Codeforces Round 32:E. Maximum Subsequence(Meet-in-the-middle)

    题目链接:E. Maximum Subsequence 用了一个Meet-in-the-middle的技巧,还是第一次用到这个技巧,其实这个技巧和二分很像,主要是在dfs中,如果数量减小一半可以节约很 ...

  4. Educational Codeforces Round 32 Maximum Subsequence CodeForces - 888E (meet-in-the-middle,二分,枚举)

    You are given an array a consisting of n integers, and additionally an integer m. You have to choose ...

  5. Educational Codeforces Round 32 Almost Identity Permutations CodeForces - 888D (组合数学)

    A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in thi ...

  6. Educational Codeforces Round 32 E 二分

    题意:从数组中选几个(任意),使他们的和modm的值最大 题解:我一开始是直接暴力写,然后就会t 其实这题可以用二分的方法写,一半数组的值用来遍历,一般数组的值用来查询. 二分查询就能把时间继续缩短 ...

  7. Educational Codeforces Round 132 (Rated for Div. 2)

    Educational Codeforces Round 132 (Rated for Div. 2) A. Three Doors 简述 题意: 有三扇门(1~3), 其中两扇门后面有对应标号门的钥 ...

  8. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  9. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

随机推荐

  1. 恢复误删除表黑科技之relay log大法

      Preface       In my previous blogs,I've demonstrated several mothods of how to rescue a dropped ta ...

  2. 添加selenium对应的jar包至pom.xml

    1.进入https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java,点开相应的版本 2.复制图中选中的代码,粘贴至 ...

  3. Megacli查看Dell服务器Raid状态

    通常我们使用的DELL/HP/IBM三家的机架式PC级服务器阵列卡是从LSI的卡OEM出来的,DELL和IBM两家的阵列卡原生程度较高,没有做太多封装,可以用原厂提供的阵列卡管理工具进行监控:而HP的 ...

  4. LDA和PCA降维的原理和区别

     LDA算法的主要优点有: 在降维过程中可以使用类别的先验知识经验,而像PCA这样的无监督学习则无法使用类别先验知识. LDA在样本分类信息依赖均值而不是方差的时候,比PCA之类的算法较优. LDA算 ...

  5. [部署开发环境][1 vagrant] vagrant部署开发环境--安装vagrant

    # 安装教程 # 安装vagrant 教程 # 准备 - windows操作系统 - VirtualBox---Win, - vagrant_1.9.3.msi - 镜像文件https://atlas ...

  6. unity射线碰撞检测+LayerMask的使用

    射线在unity中是个很方便的东西,对对象查找.多用于碰撞检测(如:子弹飞行是否击中目标).角色移动等提供了很大的帮助,在此做个总结与大家分享下 ,若有不足欢迎吐槽 好了,话补多说啦,直接进入主题: ...

  7. 将MSHFlexGrid1中记录导出为Excel

    1.添加引用Microsoft Excel 14.0 Object Library 2.编写代码部分 Private Sub Output_Click() Dim i As Integer '定义变量 ...

  8. ubuntu16.04 使用问题笔记

    1.问题: 下列软件包有未满足的依赖关系: vim : 依赖: vim-common (= 2:7.4.826-1ubuntu1) 但是 2:7.4.1689-3ubuntu1 正要被安装 E: 无法 ...

  9. 【DNS】DNS的几个基本概念

    一. 根域 就是所谓的“.”,其实我们的网址www.baidu.com在配置当中应该是www.baidu.com.(最后有一点),一般我们在浏览器里输入时会省略后面的点,而这也已经成为了习惯. 根域服 ...

  10. min_free_kbytes是内存最安全值的阈值,然后这个值是怎么影响到系统内存回收的呢?

    min_free_kbytes 内存域水印值:min_free_kbytes 当不设置的时候:sqrt(16M)=4k 4k*4 = 16k 设置内存水印值的函数是: 6792 /* 6793 * I ...