codechef September Challenge 2018 Division 2 A-F

来源:https://www.cnblogs.com/zwfymqz/archive/2018/09/17/9664759.html
-Advertisement-
Play Games

比賽鏈接 上紫啦hhh,好開心 每個題裡面都有中文翻譯,我就不說題意了。。 A 直接模擬即可 #include<cstdio> #include<algorithm> #define int long long using namespace std; const int MAXN = 1e5 + ...


比賽鏈接

上紫啦hhh,好開心

每個題裡面都有中文翻譯,我就不說題意了。。

A

直接模擬即可

#include<cstdio>
#include<algorithm>
#define int long long 
using namespace std;
const int MAXN = 1e5 + 10;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int T;
int a[MAXN], pos, Q, N;
main() {
    T = read();
    while(T--) {
        N = read(); pos = read(); Q = read();
        for(int i = 1; i <= N; i++) a[i] = i;
        while(Q--) {
            int x = read(), y = read();
            swap(a[x], a[y]);
        }
        for(int i = 1; i <= N; i++)
            if(pos == a[i]) {
                printf("%d\n", i); break;
            }
    }
}
A

B

這題我交了五遍沒過,捂臉,然而並不知道自己哪裡錯了

跟lyq說了說還被婊了一頓。。。。最後換了個寫法A了。。

直接大力特判就行,至於哪個share什麼玩意兒就讓N-1,M-1,然後判是否可行

#include<cstdio>
using namespace std;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, M, X, Y;
int pd(int N, int M) {
    /*if(N == 0 && M == 0) return 1;
    else if((N < X) || (M < Y)) return 0;
    else if(N % X == 0 && M % Y == 0) return 1;
    else return 0;*/
    if(N < 0 || M < 0) return 0;
    return N % X == 0 && M % Y == 0;
}
int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
        N = read(), M = read(), X = read(), Y = read();
        N--; M--;
        if(pd(N, M)) {puts("Chefirnemo"); continue;}
        N--; M--;
        if(pd(N, M)) {puts("Chefirnemo"); continue;}
        puts("Pofik");
    }
    return 0;
}
B

 

C

這題就有點厲害了!

結論:哥德巴赫猜想在信息學奧賽的範圍內是成立的!

也就是說,任意一個$>=4$的偶數都是合法的。

然後把奇數和$0$判掉,維護出$0, 1$的個數即可

#include<cstdio>
#define LL long long 
using namespace std;
const int MAXN = 1e6 + 10;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int T;
int N;
int a[MAXN];
LL tim[MAXN];
LL calc(LL x) {
    return x * (x - 1) / 2;
}
int main() {
  //  printf("%d", 2 ^ 4);
    T = read();
    while(T--) {
        N = read();
        for(int i = 1; i <= N;i ++) a[i] = read(), tim[a[i]]++;
        LL ans = 0, ze = 0, on = 0;
        /*for(int i = 1; i <= N; i++) {
            for(int j = i + 1; j <= N; j++) {
                int x = (a[i] ^ a[j]);
                if((!(x & 1)) && (x != 2) && (x != 0)) ans++;
            }
        }*/

        for(int i = 1; i <= N; i++)
            if(a[i] & 1) on++;
            else ze++;
        ans = calc(ze) + calc(on);
        //printf("%d\n", ans);
        LL a1 = 0;
        for(int i = 1; i <= N; i++)
            a1 += tim[a[i] ^ 2];
        ans -= a1 / 2;
        for(int i = 1; i <= N; i++) {
            ans -= (tim[a[i]] * (tim[a[i]] - 1)) / 2, tim[a[i]] = 0;
        }
        printf("%lld\n", ans);
    }
    return 0;
}
C

 

D

爆搜打出前$8$的表,不難找到規律:

最小的一定是$n, 1, 2, 3, \dots n - 1$

最大的是:$2, 3, 4, 5, n / 2, 1, 2 + n / 2, 3 + n / 2, 4 + n  /2 ...$

奇數的話還要特殊考慮一下倒數第二位

#include<cstdio>
#include<map>
#include<iostream>
#define ull unsigned long long 
#define LL long long 
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 7;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
int ans[MAXN], num;
int main() {
//    freopen("a.out", "w", stdout);
    N = read();
    
    for(int i = 2; i <= N / 2; i++) ans[++num] = i; 
    ans[++num] = 1;
    for(int i = 2; i <= N / 2; i++) ans[++num] = N / 2 + i;
    ans[++num] = 1 + N / 2;
    for(int i = 1; i <= num - 1; i++)
        printf("%d ", ans[i]);
    if(N & 1) printf("%d ", N);
    printf("%d\n", ans[num]);
    printf("%d ", N);
    for(int i = 1; i <= N - 1; i++)
        printf("%d ",i);
    return 0;
}
D

 

E

首先考慮暴力怎麼打,我們把給出的初始行列的01取反,這樣$0$的時候對應的是必勝態,$1$對應的是必敗態。

然後按博弈論的定義推,$(i, j)$若是必勝態,那麼至少有$(i - 1, j)$是必敗態 或者 $(i, j - 1)$是必敗態。

然後暴力枚舉一遍就行了,複雜度$O(NM)$

接下來的操作就比較神仙了,,打表 或 直接觀察式子可得,若第$(i, j)$個點是必敗點,那麼它所在的對角線往後的點,都是必敗點!

這樣我們就把狀態降到了$2 * M$

那最開始的必敗點怎麼求呢?

直覺告訴我們 稍加證明不難得到,這種點一定是出現在前兩行 或者前兩列。

然後就做完了。

暴力推前兩行 前兩列即可。

保險起見我推了三行三列。

#include<cstdio>
#include<cstring>
#include<vector>
#define LL long long 
using namespace std;
const int MAXN = 1e5 + 10;
inline LL read() {
    char c = getchar(); LL x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int T;
int a[4][MAXN], b[MAXN][4], N, M, f[MAXN], g[MAXN];
char A[MAXN], B[MAXN];
int main() { 
//-    freopen("a.out", "w", stdout);
    int T = read();
    while(T--) {
        scanf("%s", A + 1);
        scanf("%s", B + 1);
        M = strlen(A + 1);
        N = strlen(B + 1);
        for(int i = 1; i <= M; i++) a[0][i] = (A[i] == '1' ? 0 : 1);
        for(int i = 1; i <= 3; i++) a[i][0] = (B[i] == '1' ? 0 : 1);
        
        for(int i = 1; i <= 3; i++) b[0][i] = (A[i] == '1' ? 0 : 1);
        for(int i = 1; i <= N; i++) b[i][0] = (B[i] == '1' ? 0 : 1);
        
        memset(f, 0x7f, sizeof(f));
        memset(g, 0x7f, sizeof(g));
        
        for(int i = 1; i <= 3; i++) {
            for(int j = 1; j <= M; j++) {
                if(a[i - 1][j] == 1 || a[i][j - 1] == 1) a[i][j] = 0;//能到達必敗節點的 
                else a[i][j] = 1;
                if(a[i][j] == 1) f[j - i + 1] = min(f[j - i + 1], i);
            }
        }
        
        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= 3; j++) {
                if(b[i - 1][j] == 1 || b[i][j - 1] == 1) b[i][j] = 0;
                else b[i][j] = 1;
                if(b[i][j] == 1) g[i - j + 1] = min(g[i - j + 1], j);
            }
        }
        vector<int> ans;
        int Q = read();
        while(Q--) {
            int x = read(), y = read();
            int dy = y - x + 1,
                dx = x - y + 1;
            if(dy >= 1) {
                if(x >= f[dy]) ans.push_back(0);
                else ans.push_back(1); 
            } else {
                if(y >= g[dx]) ans.push_back(0);
                else ans.push_back(1);
            }
        }
        for(int i = 0; i < ans.size(); i++) printf("%d", ans[i]);        
        puts("");
    }

    return 0;
}
E

F

這個題我就不說啥了,challenge題嘛,xjb亂搞。

但是!!!

我TM辛辛苦苦寫了半天的貪心324分??

直接輸出$1$有400+????????????

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 我們前面文章介紹了迭代器和可迭代對象,這次介紹python的上下文管理。在python中實現了__enter__和__exit__方法,即支持上下文管理器協議。上下文管理器就是支持上下文管理器協議的對象,它是為了with而生。當with語句在開始運行時,會在上下文管理器對象上調用 __enter__ ...
  • Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1340 Accepted Submission(s): 891 Problem Des ...
  • 通用的(泛型)演算法 之 只讀演算法,寫演算法,排序演算法 只讀演算法: | 函數名 | 功能描述 | | | | | accumulate | 求容器里元素的和 | | equal | 比較2個容器里的元素 | 寫演算法 | 函數名 | 功能描述 | | | | | fill | 用給定值,覆蓋給定的範圍的元 ...
  • Spring Boot 日誌篇 1、日誌框架(故事引入) 小張;開發一個大型系統; ​ 1、System.out.println("");將關鍵數據列印在控制台;去掉?寫在一個文件? ​ 2、框架來記錄系統的一些運行時信息;日誌框架 ; zhanglogging.jar; ​ 3、高大上的幾個功能? ...
  • 此系列將記錄本人從開始到結束做物料管理系統的過程 登錄界面的設計 此博客將實現如下界面: 當用戶名或密碼沒輸入時將顯示相應的提示信息,採用java swing實現 代碼: ...
  • 數組中有一個數字出現的次數超過數組長度的一半,請找出這個數字。例如輸入一個長度為9的數組{1,2,3,2,2,2,5,4,2}。由於數字2在數組中出現了5次,超過數組長度的一半,因此輸出2。如果不存在則輸出0。 兩種方式: 1.定義一個新數組arr,遍曆數組給arr賦值,arr[元素]=出現的次數 ... ...
  • 已經有兩個月沒有寫博客了,也有好幾個月沒有看go相關的內容了,由於工作原因最近在做java以及大數據相關的內容,導致最近工作較忙,博客停止了更新,正好想撿起之前go的東西,所以找了一個源碼學習 這個也是之前用go寫日誌收集的時候用到的一個包 :github.com/hpcloud/tail, 這次就 ...
  • 目前主要功能是完成知乎視頻的下載. 在抓包和網頁分析發現有blob:https://...格式的視頻鏈接, 但是無法訪問, 不過知乎好像是m3u8格式的, 具體的我也不太清楚, 但這並不妨礙我們的下載工作. 其中ts就是被分割後的相對url, 拼接後就可以下載播放了, 不過這裡還要做的就是將所有被分 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...