http://codeforces.com/contest/888

Local Extrema【水】

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

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

【代码】:

#include<bits/stdc++.h>

using namespace std;

int main()
{
int n,a[+];
int maxn,minn;
maxn=minn=;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i];
}
for(int i=;i<=n-;i++)
{
if(a[i]>a[i+]&&a[i]>a[i-]) maxn++;
if(a[i]<a[i+]&&a[i]<a[i-]) minn++;
}
cout<<minn+maxn<<endl;
return ;
}

暴力

Buggy Robot【模拟】

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

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

【代码】:

#include<bits/stdc++.h>

using namespace std;

int main()
{
int n,min1,min2;
int l,d,u,r;
l=d=u=r=min1=min2=;
char a[];
cin>>n;
for(int i=;i<n;i++)
{
cin>>a[i];
if(a[i]=='L') l++;
else if(a[i]=='D') d++;
else if(a[i]=='U') u++;
else r++;
}
if(l&&(!r)){
printf("0\n");
return ;
}
if(r&&(!l)){
printf("0\n");
return ;
}
if(u&&(!d)){
printf("0\n");
return ;
}
if(d&&(!u)){
printf("0\n");
return ;
} if(l&&r) min1=*min(l,r);
if(u&&d) min2=*min(u,d); printf("%d\n",min1+min2);
return ;
}

被hack代码

#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N,l=,r=,u=,d=;
cin>>N;
string s;
cin>>s;
for(int i=;i<s.length();i++){
if(s[i]=='L')l++;
if(s[i]=='R')r++;
if(s[i]=='U')u++;
if(s[i]=='D')d++;
}
cout<<*(min(l,r)+min(u,d))<<endl;
}

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是出现的位置

【代码】:

#include<bits/stdc++.h>

using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double pi = acos(-1.0);
const int maxn = +;
const int mod = 1e9+;
char a[maxn];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
scanf("%s",a+);
int len=strlen(a+),ans=len;
for (int i=;i<;i++){
int tmp=;
int pos=;
for (int j=;j<=len;j++)if (a[j]==i)tmp=max(tmp,j-pos),pos=j;
tmp=max(tmp,len+-pos);
ans=min(ans,tmp);
}
printf("%d\n",ans);
return ;
}
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
4 1
output
1
input
4 2
output
7
input
5 3
output
31
input
5 4
output
76

【题意】:一个长为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 
 
【代码】:
By RoniKing, contest: Educational Codeforces Round , problem: (D) Almost Identity Permutations, Accepted, #
#include <bits/stdc++.h>
#define LL long long
using namespace std;
//const int mod=1e9+7;
const int maxn=1e3+;
LL D[maxn], C[maxn][];
int p[+];
void init()
{
D[]=;
D[]=;
for(int i=;i<maxn;i++)//错排
D[i]=((i-)*(D[i-]+D[i-]));
int i;
//for (p[0]=i=1;i<=200000;i++) p[i]=1ll*p[i-1]*i%mod;
for (int i = ; i < maxn; i++)//排列组合
{
for (int j = ; j <= min(, i); j++)
{
if (j == ) C[i][j] = ;
else
C[i][j] = (C[i-][j] + C[i-][j-]) ;
}
}
}
int main()
{
init();
int t; int n,k;
cin>>n>>k;
LL ans=;
for(LL i=;i<=n;i++)
ans = ans * i ;
LL val=;
for(int i=;i<=k;i++)
val=(val + D[i]*C[n][i]) ;
// cout<<ans<<endl;
cout<<val<<endl;
//cout<<(ans-val)<<endl; }

我的丑代码

#include<bits/stdc++.h>

using namespace std;

int main()
{
long long n,k;
cin>>n>>k;
long long ans=;
if(k>=) ans+=n*(n-)/;
if(k>=) ans+=n*(n-)*(n-)/;
if(k>=) ans+=n*(n-)*(n-)*(n-)*/;
cout<<ans;
return ;
}

简♂短

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. 程序员必备PC维修法(硬件篇)

    自检自修不是万能,但不会自检自修却万万不能.程序员修电脑还是有必要的. 情景:通电情况下,电脑主机无法启动,所有主机内部硬件无反应. 原因:1.CPU.主板.电源积尘.(出现率30%) 2.CPU.主 ...

  2. Python 3基础教程5-while循环语句

    本文开始介绍循环语句,和其他编程语言一样,Python中有while循环和for循环,这里介绍while循环. 语法: while 条件表达式为真: 做一些事情 实际生活中有很多这样的循环场景,这里举 ...

  3. bash 语言的乘法表

    #!/bin/bash ];then exit fi ; i<$; i++)); do ; j<=i; j++)); do tput setaf $j echo -ne "$j& ...

  4. IntelliJ IDEA 注释模版 输入/**后 不显示配置好的模板

    简单一句话就是 当你在live templetes里配置好以后,记住abbreviation:输入框里的字母 比如我的是cc ,我要想写注释怎么办? 在方法上输入 /*cc 然后按tab键就出来了

  5. c++知识点总结--静态与动态类型

    对象的静态类型(static type),就是它在程序中被声明时所采用的类型 对象的动态类型(dynamic type)是指“目前所指对象的类型”   vitual 函数是动态绑定而来,调用一个vir ...

  6. php学习ing

    cmd运行,表示在本地d:/php/workspace下文件映射在127.0.0.1的8080端口下,-S -t不要忘记 php -S 127.0.0.1:8080 -t E:\class_manag ...

  7. eclipse 运行错误:在类XXX中找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args) 否则 JavaFX 应用程序类必须扩展javafx.application.Application

    新建了一个类Hello: 代码: 第一次运行报错: 点击关闭该类的界面时出现: 点击是,然后再次打开,可以正确执行,结果为: 这是为什么....,后来发现了原因:是每次运行或调试前没有自动保存编辑的内 ...

  8. python 读取consul配置

    自动化通过rcp client调用远端服务接口时,都需要将远端测试服务ip.端口记录在配置文件. 但由于,服务发布或重启会导致ip.端口变动. 以下将通过python-consul 自动去读取cons ...

  9. PHP异常处理类(文件上传提示)

    知识点: 大部分时候我们的代码总有各种各样的bug,新手程序员(比如我)最经常的工作就是不停的报错和echo变量,一个好的异常处理类可以帮我们更快+更容易理解报错代码的问题,同时,异常处理还可以避免一 ...

  10. 【bzoj1899】[Zjoi2004]Lunch 午餐 dp

    题目描述 上午的训练结束了,THU ACM小组集体去吃午餐,他们一行N人来到了著名的十食堂.这里有两个打饭的窗口,每个窗口同一时刻只能给一个人打饭.由于每个人的口味(以及胃口)不同,所以他们要吃的菜各 ...