【 Educational Codeforces Round 55 (Rated for Div. 2)】 A.B.C.D.E.
前言
biubiubiu_
1861->1890
biubiubiu_
13min
27min
51min
100min
A. Vasya and Book
題意
給你一本n頁的書,當前在第x頁,想要翻到第y頁,除了不夠翻不然每次向前或者向後只能翻d頁,問最少翻幾次書可以翻到第y頁
做法
只有三種情況
x->y
x->1->y
x->n->y
對所有可行值取min即可
程式碼
#include<stdio.h>
#include<iostream>
using namespace std;
typedef long long ll;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll tmp,n,x,y,d;
scanf("%lld%lld%lld%lld",&n,&x,&y,&d);
if(x>y)
{
tmp=x-y;
}
else
{
tmp=y-x;
}
if(tmp%d==0)
{
printf("%lld\n",tmp/d);
}
else
{
ll tmp1=((x-1)/d)+((x-1)%d!=0);
ll ans=LL_INF;
if((y-1)%d==0)
{
ans=min(ans,tmp1+(y-1)/d);
}
ll tmp2=((n-x)/d)+((n-x)%d!=0);
if((n-y)%d==0)
{
ans=min(ans,tmp2+(n-y)/d);
}
if(ans==LL_INF)
{
printf("-1\n");
}
else
{
printf("%lld\n",ans);
}
}
}
return 0;
}
B. Vova and Trophies
題意
給你一個只有G,S兩種字元的字串,可以交換一次兩個位置的字元,問最終最長的連續的G可以有多少個
做法
有四種情況
第一種:只有一段連續的G,直接輸出個數
第二種:有兩段連續的G,兩段間隔為1,答案為len1+len2
第三種:有兩段連續的G,兩段間隔大於1,答案為max(len1,len2)+1
第四種:有大於等於三段連續的G、並且有兩段間隔等於一,答案等於所有間隔為一的兩段中max(len1+len2)+1
程式碼
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 1e5+5;
vector<int> v1,v2;
char str[maxn];
int main()
{
int n;
scanf("%d",&n);
scanf("%s",str+1);
int pres=-1,preg=0;
int maxx=0;
int sumg=0;
int maxxg=0;
for(int i=1;i<=n;i++)
{
if(str[i]=='G')
{
int tmp=0;
while(i<=n&&str[i]=='G')
{
tmp++;
i++;
}
i--;
if(pres==1) maxx=max(maxx,preg+tmp);
preg=tmp;
maxxg=max(maxxg,tmp);
sumg++;
}
else
{
int tmp=0;
while(i<=n&&str[i]=='S')
{
tmp++;
i++;
}
i--;
pres=tmp;
}
}
int ans=0;
if(sumg>=3) ans=max(ans,maxx+1);
if(sumg>=2) ans=max(ans,maxx);
if(sumg>=2) ans=max(ans,maxxg+1);
ans=max(ans,maxxg);
printf("%d\n",ans);
return 0;
}
C. Multi-Subject Competition
題意
給你n個數字,每個數字屬於一個組,對於每個組,可以選擇選或者不選,最終選擇一些組,每個組選出一些數字,要求每組選的數字個數相等,而且所有數字的和最大。
做法
對每組的數字sort,暴力列舉選1個,選2個…選maxx(數字最多的組的數字個數)個,
程式碼
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int s[maxn],r[maxn];
vector<vector<int> > v;
vector<int> tmp[maxn];
vector<ll> sum[maxn];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&s[i],&r[i]);
tmp[s[i]].push_back(r[i]);
}
for(int i=1;i<=m;i++)
{
if(tmp[i].size()!=0) v.push_back(tmp[i]);
}
int maxx=0;
for(int i=0
相關推薦
【 Educational Codeforces Round 55 (Rated for Div. 2)】 A.B.C.D.E.
前言
biubiubiu_
r
a
t
i
【Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies】暴力+細節題
B. Vova and Trophies
題意
給你一個只有G,S兩種字元的字串,可以交換一次兩個位置的字元,問最終最長的連續的G可以有多少個
2
【Educational Codeforces Round 55 (Rated for Div. 2) E. Increasing Frequency】滾動陣列優化暴力
E. Increasing Frequency
題意
給你一個數列,你可以選擇在[l,r]區間同時加或者減一個值, 在一次操作後,這個序列最多有多少個值等於c
做法
首先我們要想明白的是,a[l]一定是等於a[r]的 如果a[l]!=a[r],那麼我們肯定可以縮小這個區間,
Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies 【貪心 】
傳送門:http://codeforces.com/contest/1082/problem/B
B. Vova and Trophies
time limit per test
2 seconds
memory limit per test
Educational Codeforces Round 55 (Rated for Div. 2) C. Multi-Subject Competition 【vector 預處理優化】
long long i++ ins pat nds won not total mathjax 傳送門:http://codeforces.com/contest/1082/problem/C
C. Multi-Subject Competition
time limi
【Educational Codeforces Round 54 (Rated for Div. 2) E. Vasya and a Tree】 dfs+樹狀陣列
E. Vasya and a Tree
題意
給
你
一
【Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum】 數位DP
E. Segment Sum
題意
題
意
很
【 Educational Codeforces Round 53 (Rated for Div. 2) D. Berland Fair】思維題
D. Berland Fair
題意
有
n
個
【Educational Codeforces Round 53 (Rated for Div. 2)-C. Vasya and Robot】二分
Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot
題意
在
二
Educational Codeforces Round 55 (Rated for Div. 2)
sizeof force () codeforce sub ova == break eof Educational Codeforces Round 55 (Rated for Div. 2)
鏈接
A Vasya and Book
傻逼題。。註意判邊界。
#includ
Educational Codeforces Round 55 (Rated for Div. 2) A - Vasya and Book
傳送門
https://www.cnblogs.com/violet-acmer/p/10035971.html
題意:
一本書有n頁,每次只能翻 d 頁,問從x頁到y頁需要翻動幾次?
注意:往前翻最少翻到第1頁,往後翻最多翻到n頁。
題解:
一開始想找規律來著,emm
Educational Codeforces Round 55 (Rated for Div. 2) Solution
A. Vasya and Book
Solved.
三種方式取$Min$
1 #include <bits/stdc++.h>
2 using namespace std;
3
4 #define ll long long
5 #define INF 0x3
Codeforces 1082 A. Vasya and Book-題意 (Educational Codeforces Round 55 (Rated for Div. 2))
A. Vasya and Book
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
Codeforces 1082 D. Maximum Diameter Graph-樹的直徑-最長鏈-構造題 (Educational Codeforces Round 55 (Rated for Div. 2))
size cond exc ref i++ 從大到小 force round pbo
D. Maximum Diameter Graph
time limit per test
2 seconds
memory limit per test
256 me
Codeforces 1082 D. Maximum Diameter Graph-樹的直徑-最長鏈-構造題 (Educational Codeforces Round 55 (Rated for Div. 2))
D. Maximum Diameter Graph
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standa
Educational Codeforces Round 55 (Rated for Div. 2):E. Increasing Frequency
E. Increasing Frequency
題目連結:https://codeforces.com/contest/1082/problem/E
題意:
給出n個數以及一個c,現在可以對一個區間上的數同時加上或減去一個值,問最後c的最多數量為多少。
題解:
這題挺有意思的,我們通
Educational Codeforces Round 55 (Rated for Div. 2) E - Increasing Frequency(列舉+尺取)
題意
n個數,一個c值,
允許改一次區間[l,r],即把這個區間內的數同時加上或減去一個k,
問修改之後,最多有多少個c值。
思路來源
翼神%%%
題解
列舉哪個值是最後是替代c的值
c顯然不需要替代自己,預處理一下[0,n-1]區間有幾個c
對每個值跑一遍
Educational Codeforces Round 55 (Rated for Div. 2) D.Maximum Diameter Graph
題意
給定一個n,n個節點的最大度,
問是否能構成一個無向連通圖,
並求該圖的最大直徑(直徑定義為直徑上任意兩點間的距離都是該圖上的最短距離),
輸出所有具體的圖的構造邊(u,v)中的u,v。
題解
只要能構成樹就能滿足上面的條件了,而且多餘的邊顯然多
Educational Codeforces Round 55 (Rated for Div. 2) 部分題解
A. Vasya and Book:
題目
傳送門1
思路:
分三種情況討論
程式碼如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <ios