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 ...
随机推荐
- dfs.replication 参数 动态修改
首先 dfs.replication这个参数是个client参数,即node level参数.需要在每台datanode上设置.其实默认为3个副本已经够用了,设置太多也没什么用. 一个文件,上传到hd ...
- dede 转 帝国
1.转换栏目 insert into ak_enewsclass (classid,bclassid,classname,myorder,classpath,intro,classpagekey) s ...
- 四维dp 或者 剪枝 + dfs Codeforces Beta Round #6 (Div. 2 Only) D
http://codeforces.com/contest/6/problem/D 题目大意:有一队人,排成一列,每个人都有生命值,你每次可以攻击2~n位置的一个的人,假设每次攻击的位置为pos,那么 ...
- laravel使用多个数据库连接
1.配置.env文件 DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=database_name DB_USERNAME= ...
- Linq skip skipwhile take takewhile
一.Skip()跳过 static void Main(string[] args) { //skip()跳过 ,,,,,,,,,}; //跳过3条 nums.Skip().ToList().ForE ...
- wpf应用程序 打印标签
新建一个wpf应用程序,Xaml如下: <Window x:Class="CreateBarCodeDemo.MainWindow" xmlns="http://s ...
- Windsock套接字I/O模型学习 --- 第三章
1. WSAAsyncSelect 模型 WSAAsyncSelect 模型比较简单,是为了适应Windows的消息驱动环境而设置的,WSAAsyncSelect 函数自动把套接字设为非阻塞模式.MF ...
- Hibernate 系列教程15-一级缓存
Product public class Product { private Long id; private String name; Product.hbm.xml <class name= ...
- LightOJ 1030 Discovering Gold 数学期望计算
题目大意:给出长度为n的一条隧道,每个位置都有一定数量的财宝.给你一枚骰子,roll到几点就前进几步,如果即将到达的地方超过了这条隧道长度,就重新roll一次,走到n点结束.求这个过程能收获多少财宝. ...
- hiho#1128 : 二分·二分查找
input 1<=n<=1e6 1<=k<=2*1e9 a1 a2 ... an 1<=an<=2*1e9 output k存在则输出k是第几大的数,否则输出-1 ...