Ranting重新回到蓝的一场比赛

Problem A

题意:月亮的大小是按照这样的顺序排列的0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1

然后给定一串数,试判断最后一个是增加还是减少

分析:这题还被hack了,对于最后一个不是0,15,且是一个数的情况,直接输出-1,然后只有一个数是0或15,分别对应增加或减少,然后其他的

情况就分别讨论与前一个数的关系就行

 #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=;
int a[maxn];
int n;
int main()
{
while(cin>>n)
{
for(int i=;i<=n;i++)
cin>>a[i];
if(a[n]==){
cout<<"UP"<<endl;
continue;
}
if(a[n]==){
cout<<"DOWN"<<endl;
continue;
}
if(n==){
cout<<"-1"<<endl;
continue;
}
if(a[n-]<a[n]){
cout<<"UP"<<endl;
}else{
cout<<"DOWN"<<endl;
}
}
return ;
}

Problem B

题意:全是由r和b组成的字符串,要改成交错的,问至少要操作多少次

分析:这题可以(1)分别统计如果奇数位全为r,偶数位全为b要修改的次数,取二者当中的最大;(2)统计如果奇数位全为b,偶数位全为r要修改的次数,取二者当中的最大;最后再来求(1)和(2)的最小

 #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=;
int a[maxn];
int n;
int main()
{
while(cin>>n)
{
for(int i=;i<=n;i++){
char ch;
cin>>ch;
if(ch=='b'){
a[i]=;
}else{
a[i]=;
}
} int cntb=,cntr=;
int ans=<<;
int tot=;
for(int i=;i<=n;i++){
if(i%==){
if(!a[i]){
cntb++;
}
}
}
for(int i=;i<=n;i++){
if(i%==){
if(a[i]){
cntr++;
}
}
}
while(cntr&&cntb) tot++,cntr--,cntb--;
tot+=cntr+cntb;
ans=min(ans,tot); int cntr1=,cntb1=;
int tot1=;
for(int i=;i<=n;i++){
if(i%==){
if(a[i])
cntb1++;
}
}
for(int i=;i<=n;i++){
if(i%==){
if(!a[i])
cntr1++;
}
}
while(cntb1&&cntr1) tot1++,cntr1--,cntb1--;
tot1+=cntr1+cntb1;
ans=min(ans,tot1);
cout<<ans<<endl;
}
return ;
}

Problem C

暂时没做

Problem E

题意:给定一个数组,1表示对区间[l,r]每个数加上x,2表示统计[l,r]中已元素为下标的斐波拉契的和

分析:矩阵快速幂+线段树 ,这题是很好的模板题,get一份很好的模板

 //
// main.cpp
// E
//
// Created by wanghan on 16/9/26.
// Copyright © 2016年 wanghan. All rights reserved.
// #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cctype>
#include<map>
#include<set>
#include<deque>
using namespace std;
const int N=;
const long long MOD=1e9+;
const int maxn=1e5+;
int n,m; //矩阵快速幂
struct Matrix{
int a[][];
Matrix(){
memset(a,,sizeof(a));
}
void init(){
for(int i=;i<N;i++)
for(int j=;j<N;j++)
a[i][j]=(i==j);
}
Matrix operator + (const Matrix &B)const{
Matrix C;
for(int i=;i<N;i++)
for(int j=;j<N;j++)
C.a[i][j]=(a[i][j]+B.a[i][j])%MOD;
return C;
}
Matrix operator * (const Matrix &B)const{
Matrix C;
for(int i=;i<N;i++)
for(int k=;k<N;k++)
for(int j=;j<N;j++)
C.a[i][j]=(C.a[i][j]+1LL*a[i][k]*B.a[k][j])%MOD;
return C;
}
Matrix operator ^ (const int &t)const{
Matrix A=(*this),res;
res.init();
int p=t;
while(p){
if(p&) res=res*A;
A=A*A;
p>>=;
}
return res;
}
}One,Two; //线段树部分
Matrix sum[maxn<<],add[maxn<<];
void PushUp(int rt){
sum[rt]=sum[rt<<]+sum[rt<<|];
}
void Build(int l,int r,int rt){
add[rt].init();
if(l==r){
sum[rt]=One;
return;
}
int mid=(l+r)/;
Build(l,mid,rt<<);
Build(mid+,r,rt<<|);
PushUp(rt);
} void PushDown(int rt,int l,int r)
{
if(add[rt].a[][]!=){
int mid=(l+r)/;
add[rt<<]=add[rt<<]*add[rt];
sum[rt<<]=(sum[rt<<]*add[rt]);
add[rt<<|]=(add[rt<<|]*add[rt]);
sum[rt<<|]=(sum[rt<<|]*add[rt]);
add[rt].init();
}
}
void Update(int L,int R,Matrix& v, int l,int r,int rt){
if(l>R||r<L)
return;
if(L<=l&&r<=R){
add[rt]=add[rt]*v;
sum[rt]=sum[rt]*v;
return;
}
PushDown(rt, l, r);
int mid=(l+r)/;
Update(L, R, v, l, mid, rt<<);
Update(L, R, v, mid+, r, rt<<|);
PushUp(rt);
}
int Query(int L,int R,int l,int r,int rt){
if(l>R||r<L)
return ;
if(L<=l&&r<=R)
return sum[rt].a[][];
PushDown(rt, l, r);
int mid=(l+r)/;
return (Query(L, R, l, mid, rt<<)
+Query(L, R, mid+, r, rt<<|))%MOD;
} //初始化斐波拉契数列
void Init(){
One.a[][]=,One.a[][]=;
One.a[][]=,One.a[][]=;
Two.a[][]=,Two.a[][]=;
Two.a[][]=,Two.a[][]=;
} int tt[maxn];
int main()
{
Init();
while(scanf("%d%d",&n,&m)!=EOF)
{
Build(, n, );
for(int i=;i<=n;i++)
scanf("%d",&tt[i]);
Matrix tmp;
for(int i=;i<=n;i++){
tmp=Two^(tt[i]-);
Update(i, i, tmp, , n, );
}
for(int i=;i<=m;i++){
int num,x,y,w;
scanf("%d",&num);
if(num==){
scanf("%d%d%d",&x,&y,&w);
tmp=Two^(w);
Update(x, y, tmp, , n, );
}else{
scanf("%d%d",&x,&y);
cout<<Query(x, y, , n, )<<endl;
}
}
}
return ;
}

Codeforces#373 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 373 A - Efim and Strange Grade(算数模拟)

    codeforces 373 A - Efim and Strange Grade(算数模拟) 原题:Efim and Strange Grade 题意:给出一个n位的实型数,你可以选择t次在任意位进 ...

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

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

  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. httpclient调用方法

    /**  * GET请求  *   * @param url  *            请求url,参数拼在请求串中  */ public static String get(String url) ...

  2. network: 思科-华为光模块

    思科-华为光模块的分类比较   摘要:本文介绍:思科GLC-SX-MM,GLC-LH-SM光模块等产品参数与图片,华为光模块的型号与分类等知识. 光模块分类与介绍 一.思科厂家 1.多模光模块 型号: ...

  3. 使用HAXM加速Android虚拟机

    Android虚拟机在支持Intel VT技术的CPU上,可以使用HAXM(Hardware Accelerated Execution Manager)得到硬件加速支持,使得虚拟机运行速度得到极大提 ...

  4. 据磁力链获得BT种子

    最近研究了一下磁力链magnet和BT种子torrent文件之间的相互转换.其实通过torrent文件获得磁力链实现起来比较简单,但反过来并非是一个可逆的过程,磁力链转BT种子理论上来说是不可能实现的 ...

  5. prototype小解

    prototype由来 在理解prototype前,首先得理解js面向对象编程的私有变量.私有函数,静态变量.静态函数,以及实例变量,实例函数 私有变量,私有函数 函数内部通过var定义的变量 fun ...

  6. mysql 修改 添加 删除 表字段

    添加表的字段    alter table 表名  add  字段名  字段的类型 例子:        alter table table1 add transactor varchar(10) n ...

  7. 提高MySQL查询速度

    参考百度知道 关于mysql处理百万级以上的数据时如何提高其查询速度的方法 最近一段时间由于工作需要,开始关注针对Mysql数据库的select查询语句的相关优化方法. 由于在参与的实际项目中发现当m ...

  8. 利用apache组件实现文件上传

    实现文件上传需要引入: commons-fileupload-1.3.2.jar commons-io-2.5.jar commons-logging-1.2.jar <!DOCTYPE htm ...

  9. java 对象的上转型对象(父类)

    Example5_10.java class 类人猿 { void crySpeak(String s) { System.out.println(s); } } class People exten ...

  10. linux和windows之间上传 下载文件 非ftp方式

    用 命令 rz   上传   sz 下载  文件夹加上 -r  rz上传替换时用 -y   谁用谁知道 两台linux传 : scp -r  文件夹  username@ip:路径  (如果传输文件就 ...