这是一场非常需要总结的比赛,交了3题,最后终测的时候3题全部没过,一下掉到了绿名,2333

Problem A

题意:给定区间[l1,r1],[l2,r2],然后给定一个整数k,求区间当中相交的元素,k这个点不可算

分析:画图即可得出答案,注意两个l1和r2,以及r1和l2刚好重合的情况,赛场上就是漏电这种情况

 //
// main.cpp
// Codeforces
//
// Created by wanghan on 16/9/14.
// Copyright © 2016年 wanghan. All rights reserved.
// #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<cctype>
using namespace std;
long long l1,r1,l2,r2,k;
int main(int argc, const char * argv[]) {
// insert code here...
while(cin>>l1>>r1>>l2>>r2>>k)
{
if(l1<=l2){
if(l2>r1){
cout<<""<<endl;
}else if(l2==r1){
if(l2==k)
cout<<""<<endl;
else cout<<""<<endl;
}
else{
if(r1>=r2){
if(k>=l2&&k<=r2)
cout<<r2-l2<<endl;
else
cout<<r2-l2+<<endl;
}else{
if(k>=l2&&k<=r1){
cout<<r1-l2<<endl;
}else{
cout<<r1-l2+<<endl;
}
}
}
}
else {
if(l1>r2){
cout<<""<<endl;
}else if(l1==r2)
{
if(k==l1)
cout<<""<<endl;
else
cout<<""<<endl;
}
else{
if(r2>=r1){
if(k>=l1&&k<=r1)
cout<<r1-l1<<endl;
else
cout<<r1-l1+<<endl;
}else{
if(k>=l1&&k<=r2)
cout<<r2-l1<<endl;
else
cout<<r2-l1+<<endl;
}
}
}
}
return ;
}

Problem B

题意:给定一串数,问是否可以都加上或者减去同一个数1次或0次,让所有数最后都相等

分析:用set进行维护,统计其中不同元素的个数,若小于3个,肯定可以;若大于3个,肯定不行;若等于3个,判断一下是否中间一个是另外两个的平均数

 //
// main.cpp
// CodeforcesB
//
// Created by wanghan on 16/9/14.
// Copyright © 2016年 wanghan. All rights reserved.
// #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<cctype>
using namespace std;
const int maxn=;
int a[maxn];
int n;
int main()
{
while(cin>>n)
{
set<int> s;
set<int>::iterator iter;
for(int i=;i<=n;i++){
cin>>a[i];
int x=a[i];
s.insert(x);
}
if(s.size()<){
cout<<"YES"<<endl;
}else if(s.size()>){
cout<<"NO"<<endl;
}else{
int b[];
int cnt=;
for(iter=s.begin();iter!=s.end();iter++){
b[cnt]=*iter;
cnt++;
}
int num=b[]+b[];
if(b[]*==num)
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
}

Problem C

题意:+代表往集合里面加一个元素,-代表删除集合里面的这个元素,每个元素按位%2得到一个,?表示统计集合当中有多少个数按位%2等于要求的值

分析:用map来进行维护,+时p[num]++,-时p[num]--,?求出p[num]的个数即可

 //
// main.cpp
// Codeforces
//
// Created by wanghan on 16/9/17.
// Copyright © 2016年 wanghan. All rights reserved.
// #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<algorithm>
#include<map>
using namespace std;
map<long long,int> p;
int t;
int main()
{
cin>>t;
while(t--)
{
char ch[];
char s[];
scanf("%s %s",ch,s);
int len;
if(ch[]=='+'||ch[]=='-'){
long long ans=;
len=strlen(s);
for(int i=;i<len-;i++){
long long t=(s[i]-'');
ans=ans+t%;
ans*=;
}
ans+=(s[len-]-'')%;
//cout<<ans<<endl;
if(ch[]=='+') p[ans]++;
else p[ans]--;
}else{
long long ans1=;
len=strlen(s);
for(int i=;i<len-;i++){
long long t1=(s[i]-'');
ans1=ans1+t1;
ans1*=;
}
ans1+=(s[len-]-'')%;
cout<<p[ans1]<<endl;
}
}
}

Problem D

交互题,不会做

Problem E

题意:对一个序列里面的每个元素,可以加1或者减1,问怎么样才能经过最少操作使其变成严格上升的

分析:对于非严格上升的情况参看POJ3666,下面我来说说严格上升的的情况,因为a[i]<a[i+1],所以a[i]<=a[i+1]-1,故a[i]-i<=a[i+1]-(i+1),这样就又回到了非严格上升,直接做即可

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
long long a[maxn],b[maxn];
long long dp1[maxn][maxn];
int n;
bool cmp(int x,int y)
{
return x>y;
}
int main()
{
while(cin>>n)
{
for(int i=;i<n;i++)
cin>>a[i];
for(int i=;i<n;i++){
a[i]-=i;
b[i]=a[i];
}
sort(b,b+n); //求上升的情况
memset(dp1,,sizeof(dp1));
for(int i=;i<n;i++){
long long minx=dp1[i][];
for(int j=;j<n;j++){
minx=min(minx,dp1[i][j]);
dp1[i+][j]=minx+abs(a[i]-b[j]);
}
}
long long min_up=dp1[n][];
for(int i=;i<n;i++){
min_up=min(min_up,dp1[n][i]);
}
cout<<min_up<<endl;
}
return ;
}

Codeforces#371 Div2的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces Round 371 Div2 B.Passwords

    原题: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  9. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

随机推荐

  1. HTML与DOM BOM javascript

    1.什么是DOM? 简单说就是DOM规定了HTML,XML等的一些文档映射规范,使JavaScript可以根据这些规范来进行获取元素,在元素上进行各种操作,使得用户页面可以动态的变化,从而大大使页面的 ...

  2. mongodb启动

    MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可护展的高性能数据存储解决方案.MongoDB是一款分布式文档数据库,支持类似关型数据库的主从结构,文档以二进制J ...

  3. Java学习笔记之接口和抽象类

    接口(interface)1.interface创建一个接口,implements实现接口 interface jiekou{} class lie implements jiekou{}2.接口可以 ...

  4. git 使用系列(二)---- 分支和合并

    Branching and Merging The Git feature that really makes it stand apart from nearly every other SCM o ...

  5. 【Tomcat】Tomcat配置之请求字符串编码

    默认情况下,如果tomcat中部署的webservice或者web网站需要有中文的请求参数,而这时候我们直接在浏览器中输入中文那么接受到的将是乱码,无法达到我们的需求,这时候我们就需要对Tomcat的 ...

  6. OpenGL------显示列表

    我们已经知道,使用OpenGL其实只要调用一系列的OpenGL函数就可以了.然而,这种方式在一些时候可能导致问题.比如某个画面中,使用了数千个多边形来表现一个比较真实的人物,OpenGL为了产生这数千 ...

  7. HDU 5234 Happy birthday 动态规划(三维数组)

    题目大意:过生日,有一个N*M的表格,每个位置都有一块一定重量的蛋糕你可以选择吃完或者不吃,从(1,1)走到(n,m),每次只能向右走或向下走,最多能吃k重量的蛋糕.问你最多能吃多少蛋糕. 题目思路: ...

  8. php实现echo json_encode正确显示汉字

    <?php header('Content-type: text/html; charset=utf-8'); /* function showmessage($msg = '', $redir ...

  9. 学习笔记——组合模式Composite

    组合模式,典型的层次结构. 与装饰器类图相似. 区别在于:装饰器模式是为了在接口中增加方法,而组合模式在于层次元素的叠加. ConcreteComponent就是中间结点,可以包含更多的Concret ...

  10. 转:透析QTP自动化测试框架SAFFRON

    1.为什么要使用框架? 框架是一组自动化测试的规范.测试脚本的基础代码,以及测试思想.惯例的集合.可用于减少冗余代码.提高代码生产率.提高代码重用性和可维护性.例如QTestWare就是QTP自动化测 ...