1. 程式人生 > >Codeforces Round #395 (Div. 2) 題解

Codeforces Round #395 (Div. 2) 題解

比賽連結:

本次比賽解決3題(好水呀QAQ)

A. Taymyr is calling you

水題暴力

程式碼:

#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>#include<vector>#include<stack>#include<ctime>#include<bitset>#include<cstdlib>#include<cmath>
#include<set>#include<list>#include<deque>#include<map>#include<queue>#defineMax(a,b)((a)>(b)?(a):(b))#defineMin(a,b)((a)<(b)?(a):(b))usingnamespace std;typedeflonglong ll;typedeflongdouble ld;constdouble eps =1e-6;constdouble PI = acos(-1);constint mod =1000000000+7;const
int INF =0x3f3f3f3f;// & 0x7FFFFFFF 0xcfconstint seed =131;const ll INF64 = ll(1e18);constint maxn =100;int T,n,m,z;int main(){// ios::sync_with_stdio(false);// srand((unsigned)time(NULL));// freopen("out.txt","w",stdout);// freopen("in.txt","r",stdin);// scanf("%d",&T); scanf("%d%d%d",&
n,&m,&z);int ans =0;for(int i =1; i <= z; i++){if(i % n ==0&& i % m ==0)++ans;} printf("%d\n", ans);return0;}

B. Timofey and cubes

從兩邊向中間,根據變換次數奇偶來改變

程式碼:

#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>#include<vector>#include<stack>#include<ctime>#include<bitset>#include<cstdlib>#include<cmath>#include<set>#include<list>#include<deque>#include<map>#include<queue>#defineMax(a,b)((a)>(b)?(a):(b))#defineMin(a,b)((a)<(b)?(a):(b))usingnamespace std;typedeflonglong ll;typedeflongdouble ld;constdouble eps =1e-6;constdouble PI = acos(-1);constint mod =1000000000+7;constint INF =0x3f3f3f3f;// & 0x7FFFFFFF 0xcfconstint seed =131;const ll INF64 = ll(1e18);constint maxn =2e5+10;int T,n,m,z,a[maxn];int main(){//    ios::sync_with_stdio(false);//    srand((unsigned)time(NULL));//    freopen("out.txt","w",stdout);//    freopen("in.txt","r",stdin);//    scanf("%d",&T);

    scanf("%d",&n);for(int i =1; i <= n; i++){
        scanf("%d",&a[i]);}for(int i =1; i <= n/2; i++){if(i&1) swap(a[i], a[n-i+1]);}for(int i =1; i <= n; i++){
        printf("%d%c", a[i], i==n?'\n':' ');}return0;}

C. Timofey and a tree

思路:

隨便找一個根做dfs序, 然後建立線段樹維護區間最大最小值, 再dfs一遍, 列舉每個點做為根, 那麼把線段分成了一些區間,  如果區間最大最小值相等, 那麼就只有一種顏色。

細節參見程式碼:

#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>#include<vector>#include<stack>#include<ctime>#include<bitset>#include<cstdlib>#include<cmath>#include<set>#include<list>#include<deque>#include<map>#include<queue>#defineMax(a,b)((a)>(b)?(a):(b))#defineMin(a,b)((a)<(b)?(a):(b))usingnamespace std;typedeflonglong ll;typedeflongdouble ld;constdouble eps =1e-6;constdouble PI = acos(-1);constint mod =1000000000+7;constint INF =0x3f3f3f3f;// & 0x7FFFFFFF 0xcfconstint seed =131;const ll INF64 = ll(1e18);constint maxn =2e5+10;int T,n,m,z,a[maxn],in[maxn],idex =0, out[maxn], minv[maxn<<2], maxv[maxn<<2];int ans;bool ok;void pushup(int o){
    minv[o]= min(minv[o<<1], minv[o<<1|1]);
    maxv[o]= max(maxv[o<<1], maxv[o<<1|1]);}void build(int l,int r,int o){
    minv[o]= INF;
    maxv[o]=-INF;if(l == r){
        minv[o]= maxv[o]= a[l];return;}int mid =(l + r)>>1;
    build(l, mid, o<<1);
    build(mid+1, r, o<<1|1);
    pushup(o);}int querymin(int L,int R,int l,int r,int o){if(L <= l && r <= R){return minv[o];}int mid =(l + r)>>1;int ans = INF;if(L <= mid) ans = min(ans, querymin(L, R, l, mid, o<<1));if(mid < R) ans = min(ans, querymin(L, R, mid+1, r, o<<1|1));return ans;}int querymax(int L,int R,int l,int r,int o){if(L <= l && r <= R){return maxv[o];}int mid =(l + r)>>1;int ans =-INF;if(L <= mid) ans = max(ans, querymax(L, R, l, mid, o<<1));if(mid < R) ans = max(ans, querymax(L, R, mid+1, r, o<<1|1));return ans;}vector<int> g[maxn];int c[maxn];void dfs(int u,int fa){int len = g[u].size();
    in[u]=++idex;
    a[idex]= c[u];for(int i =0; i < len; i++){int v = g[u][i];if(v == fa)continue;
        dfs(v, u);}
    out[u]= idex;}void dp(int u,int fa){int len = g[u].size();bool flag =true;if(u !=1){int mincur = INF;int maxcur =-INF;int id = in[u]-1, id2 = out[u]+1;
        mincur = min(querymin(1, id,1, n,1), querymin(id2, n,1, n,1));
        maxcur = max(querymax(1, id,1, n,1), querymax(id2, n,1, n,1));if(mincur != maxcur) flag =false;}for(int i =0; i < len; i++){int v = g[u][i];if(v == fa)continue;int mincur = querymin(in[v], out[v],1, n,1);int maxcur = querymax(in[v], out[v],1, n,1);if(mincur != maxcur) flag =false;
        dp(v, u);}
            
           

相關推薦

Codeforces Round #395 (Div. 2) 題解

比賽連結: 本次比賽解決3題(好水呀QAQ) A. Taymyr is calling you 水題暴力 程式碼: #include<cstdio>#include<cstring>#include<algorithm>#include

Codeforces Round #395 (Div. 2)

滿足 sed ace 是我 ret dfs include 裏的 思路 今天自己模擬了一套題,只寫出兩道來,第三道時間到了過了幾分鐘才寫出來,啊,太菜了。 A. Taymyr is calling you 水題,問你在z範圍內 兩個序列 n,2*n,3*n......

Codeforces Round #441 Div. 2題解

-- 開始 name getch string ast clu 之間 n-n   比賽的時候E調了好久...F沒時間寫T T   A:直接走到短的路上來回走就好了 #include<iostream> #include<cstring>

Codeforces Round #447 (Div. 2) 題解

強連通分量 統計 題解 urn spa 最大 ret num 所有 Problem A 直接暴力,當然我O(n)過的。 #include <bits/stdc++.h> using namespace std; #define rep(i,

Codeforces Round #459 (Div. 2)題解

urn 不用 blog 所有 truct 不存在 pac namespace edge 補題 codeforces 918C 題意 給定一個含有通配符?和()的字符串,問有多少子串是括號匹配的 解題思路 首先考慮不用棧求括號匹配的方法: bool solve(char* s

Codeforces Round #461 (Div. 2) 題解

產生 mat 是否 amp %d str print sin 輸出 Codeforces Round #461 (Div. 2) Codeforces 922C 題意 給定\(n,k \le 10^{18}\),判斷是否對於所有的$ i \le k,n mod i$都是不同

Codeforces Round #462 (Div. 2)題解

題解 codeforce printf 除法 main org def con 一輪 Codeforces Round #462 (Div. 2) B題……我固執的認為1e18是18位數,導致被hack,花了20分鐘才檢查出這個錯誤,很僵硬 Codeforces 934C

Codeforces Round #520 (Div. 2) 題解

A. A Prank 題目: 傳送門 此題要考慮兩種特殊情況,一種是第一個數為1,另一個是最後一個數為1000. 程式碼如下: #include <cstdio> #include <cstring> #include <algorithm>

Codeforces Round #524 (Div.2)題解

題解 CF1080A 【Petya and Origami】 這道題其實要我們求的就是 \[\lceil 2*n/k \rceil + \lceil 5*n/k \rceil + \lceil 2*n/k \rceil\] 然後就做完了 # include <bits/stdc++.h> #

【暴力搜尋】【莫隊演算法】【貪心】[Codeforces Round #340 (Div. 2) ]題解報告

A. Elephant #include <cstdio> int main(){ int n; scanf("%d", &n); printf("

Codeforces Round #259 (Div. 2) 題解

A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input outp

CodeForcesCodeForces Round #460 (Div. 2) 題解

【比賽連結】【題解連結】【A】Supermarket【思路要點】選取單價最低的店進行購買。時間複雜度\(O(N)\)。【程式碼】#include<bits/stdc++.h> using namespace std; const int MAXN = 5005;

Codeforces Round #525 (Div. 2)題解

Codeforces Round #525 (Div. 2)題解 題解 CF1088A 【Ehab and another construction problem】 依據題意列舉即可 # include <bits/stdc++.h> int main() { int x;

Codeforces Round #499 (Div. 2) 題解

A 給一堆可用的字母,字母權值等於字母序號(a=1 b=2…),從小到大選一些字母出來排列,但是後一個和前一個至少要隔1個(a可以接c不能接a,b),一共選n個,問最小權值和。標記一下哪些字母出現瞭然後從小到大來一遍就好了。 B 有一些編了號

Codeforces Round #534 (Div. 2)題解

vector 固定 開始 pro 統計 print 答案 一行 end Codeforces Round #534 (Div. 2)題解 A. Splitting into digits 題目大意 將一個數字分成幾部分,幾部分求和既是原數,問如何分可以使得分出來的各個數之間

Codeforces Round #539 (Div. 2) 題解

排序 多少 href include 只需要 偶數 possible 中間 pan Codeforces Round #539 (Div. 2) 題目鏈接:https://codeforces.com/contest/1113 A. Sasha and His Trip

CodeCraft-19 and Codeforces Round #537 (Div. 2) 題解

print line 就是 class swa bit 自己 != 方程 傳送門 D. Destroy the Colony 首先明確題意:除了規定的兩種(或一種)字母要在同側以外,其他字母也必須在同側。 發現當每種字母在左/右邊確定之後,方案數就確定了,就是分組的方案數

Codeforces Round #541 (Div. 2) 題解

pso 很多 spa rop center blank .com noi 二維 Codeforces Round #541 (Div. 2) 題目鏈接:https://codeforces.com/contest/1131 A. Sea Battle 題意: 給出兩

Codeforces Round #553 (Div. 2) 題解

scanf turn 讓我 typedef 出了 lap ide std 貢獻 昨晚深夜修仙上紫記,雖然不錯還是很有遺憾的。 A. Maxim and Biology 看完就會做的題,然而手速跟不上 #include<cstdio> #inclu

題解——Codeforces Round #508 (Div. 2) T2 (構造)

pre string col tdi push_back size std tor include 按照題意構造集合即可 註意無解情況的判斷 #include <cstdio> #include <algorithm> #include