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 ...
随机推荐
- reflow和repaint
Web页面运行在各种各样的浏览器当中,浏览器载入.渲染页面的速度直接影响着用户体验 简单地说,页面渲染就是浏览器将html代码根据CSS定义的规则显示在浏览器窗口中的这个过程.先来大致了解一下浏览器都 ...
- php之PDO使用【转载】
<?php $dbh = new PDO('mysql:host=localhost;dbname=access_control', 'root', ''); $dbh->setAttri ...
- QProcess 进程类—调用外部程序
http://blog.csdn.net/newbee520/article/details/8279101 启动一个新的进程的操作非常简单,只需要将待启动的程序名称和启动参数传递给start() ...
- AVFoundation(二)---MPMusicPlayerController
话不多说,直接上代码,代码中详细介绍了如何初始化,并设置一些常用的属性. /** * MPMusicPlayerController用于播放音乐库中的音乐 */ /** * 初始化MPMusicPla ...
- 【转】curl 查看一个web站点的响应时间(rt)
原文: http://blog.csdn.net/caoshuming_500/article/details/14044697 1. curl 查看web站点rt curl -o /dev/null ...
- Jquery树控件ZTree异步加载
异步加载的意思就是: 当点击展开树节点时,才去请求后台action返回点击节点的子节点数据并加载. 这里面主要设计ztree的setting变量的async属性设置: var setting = { ...
- 同步 异步 AJAX JS
jQuery:$post.$get.$ajax与php,实现异步加载 什么是异步加载? 整个最通俗的说法就是将另外一个页面上的数据通过append() 或者 html()等函数插入到本页上.纯js写法 ...
- ServletConfig与ServletContext对象(接口)
ServletConfig:封装servlet的配置信息. 在Servlet的配置文件中,可以使用一个或多个<init-param>标签为servlet配置一些初始化参数. <ser ...
- About struct in C
something new: to set value in struct can be in case i cannot view picture.. i write the snippet her ...
- hdu 1560 DNA sequence(迭代加深搜索)
DNA sequence Time Limit : 15000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total ...