这是一场非常需要总结的比赛,交了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. Head First - 01.策略模式(Strategy Pattern)

    策略模式定义了算法族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化独立于使用算法的客户. 当你需要给朋友留下深刻印象,或是影响关键主管的决策时,请使用“这个”定义!  设计原则: 1.找出 ...

  2. perl的USE和require

    来源: http://www.cnblogs.com/itech/archive/2010/11/22/1884345.html 相同: 都可以用来引用module(.PM). 不同: 1) 区别在于 ...

  3. java 静态方法和单例模式的区别

    1.加载时间 首先明白内存问题 Java内存分为:堆内存.栈内存.方法区(静态区和非静态区).本地方法区 无论是静态方法还是非静态方法,在内存中都只有一份分别位于方法区的静态区和非静态区:非静态方法在 ...

  4. 【dp 背包变形】 poj 1837

    #include <cstdio> #include <memory.h> #include<iostream> using namespace std; ][]; ...

  5. Stammering Aliens

    Stammering Aliens Time Limit: 2000MS   Memory Limit: 65536K       Description Dr. Ellie Arroway has ...

  6. st-Spanning Tree

    st-Spanning Tree time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...

  7. Flask architecture

    论文The Flask Security Architecture: System Support for Diverse Security Policies 介绍了Flask architectur ...

  8. linux的学习系列 7---管道和过滤器

    有时候,我们可以把两个命令连起来使用,一个命令的输出作为另一个命令的输入,这就叫做管道.为了建立管道,需要在两个命令之间使用竖线(|)连接. 管道是Linux进程之间一种重要的通信机制:除了管道,还有 ...

  9. THOUGHTS: programming in linux... with third_party open sources... methods

    Actually I do not have experiences in programming with open sources/third party libs.. in linux.. I ...

  10. g++ 编译c文件

    //编译c文件为.o文件 g++ -c virify.c //打包.o文件为.a静态库文件 ar crv libandroid_um36_virify.a virify.o //将静态库.a文件编译进 ...