Codeforces#371 Div2
这是一场非常需要总结的比赛,交了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的更多相关文章
- Codeforces #180 div2 C Parity Game
		// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ... 
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
		Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ... 
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
		Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ... 
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
		Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ... 
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
		Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ... 
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
		# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ... 
- Codeforces Round 371 Div2 B.Passwords
		原题: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard in ... 
- Codeforces #263 div2 解题报告
		比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ... 
- codeforces #round363 div2.C-Vacations (DP)
		题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ... 
随机推荐
- Hadoop2.6.0  动态增加节点
			本文主要从基础准备,添加DataNode和添加NodeManager三个部分详细说明在Hadoop2.6.0环境下,如何动态新增节点到集群中. 基础准备 在基础准备部分,主要是设置hadoop运行的系 ... 
- zf-关于更换页面,的各种问题。
			问题1:找不到common 这个变量(集合)与layer这个js文件. 这里的common 就是一个方法集合,声明var common; common.abc = function(参数1,参数2, ... 
- 设置TabBar分栏控制器上图片的大小问题
			我们都知道,iOS因为屏幕分辨率的问题,UID在交付我们iOS开发人员程序配图的时候,一般是三套图,分别对应三种不同的分辨率,对不同size的屏幕系统会自动使用不同像素的图片,我们只需要在命名时给三套 ... 
- properties 配置文件如何换行
			在使用properties配置文件的时候我们经常碰到如下两个问题 1:当a=b中的b值内容特别长的时候为了阅读方便我们手动换行,但如果我们直接回车那么后面的数据就会丢失.那如何解决呢? 例如: a=a ... 
- iOS字符串转化成CGFloat
			NSString *str = @"abc"; [str floatValue]; 
- c++绘图软件<一>
			准备写一个绘图软件,参考了三层架构(表现层.业务逻辑层.数据访问层). //////////////////////////////////////////////////////////////// ... 
- L2,breakfast or lunch
			express: what a day多么糟糕的天气 I‘m coming to see you我将要来看你 what a lot of trouble he is causing他犯了多少错误啊 w ... 
- java OPENCV 连通域,   Imgproc.findContours 例子,参数说明
			http://stackoverflow.com/questions/29491669/real-time-paper-sheet-detection-using-opencv-in-android/ ... 
- java邮件收发
			http://blog.csdn.net/ycg01/article/details/1394465 java邮件收发 标签: javaimportexceptionnulluserclass 200 ... 
- 手机号码抽奖系统(JS)
			<html><head><title>手机号码抽奖</title><meta http-equiv="Content-Type" ... 
