洛谷10月月賽R2·浴谷八連測R4

這裏寫圖片描述

Problem A. 逃避 (nigeru.c/cpp/pas)
Input file: nigeru.in
Output file: nigeru.out
Time limit: 1 second
Memory limit: 8 megabytes

給定一篇只含有大小寫字母,空格以及
′ . ′ (不含引號)的長度爲 L 的文章。文章被若干個 ′ . ′
劃分
成若干個句子,句子被若干個空格劃分成單詞。你需要將文章中每個句子第一個單詞的首字母改成大寫,
其他一律小寫,空格與
′ . ′
需原樣輸出。注意,可能存在某個句子中沒有單詞,或者某兩個單詞之間有多
個空格。

Input
一行,表示原串。
Output
一行,表示你的回答。

Examples

nigeru. wa.haji.
Nigeru. Wa.Haji.
.. .nI noip WEn le .NICE broO..
.. .Ni noip wen le .Nice broo..
Notes
測試點編號 限制與約束
1,2,3,4,5 L ≤ 10^3
6,7,8,9,10 L ≤ 10^5

Problem B. 可恥 (wa.c/cpp/pas)
Input file: wa.in
Output file: wa.out
Time limit: 1 second
Memory limit: 8 megabytes

給定一個長度爲偶數的排列 p,你每次可以選取 p 排列中相鄰的兩個元素,假如分別是 x 和 y,那
麼把 x 和 y 加入一個序列 q 的末尾,並將 x 和 y 從排列 p 中刪除。重複上述過程,直到 p 中沒有元素,
顯然最終 q 序列也是一個排列。例如 p = (1,3,2,4),第一次可以選取 3,2 這兩個元素加入 q,並且從 p
中刪除,此時 p = (1,4),第二次可以選取 1,4 這兩個元素加入 q,此時 p 爲空,q = (3,2,1,4)。觀察上
述過程,最終 q 序列可能會有很多方案,請你輸出所有可能方案中,q 的字典序最大的。
字典序的比較方式如下,假設有兩個長度同爲 n 的序列 a,b。我們找到最大的 t,使得對於 ∀i ≤ t,
a i = b i 。之後比較 a t+1 與 b t+1 ,如果 a t+1 < b t+1 ,我們就認爲 a 的字典序比 b 小,反之亦然。

Input
第一行包含一個正整數 n。第二行 n 個數,表示排列 p。
Output
一行 n 個數,表示字典序最大的序列 q。

Examples
4
3 1 4 2
4 2 3 1

6
6 5 4 1 3 2
6 5 4 1 3 2

Notes
測試點編號 限制與約束
1,2 n ≤ 10
3,4,5,6 n ≤ 10^3
7,8,9,10 n ≤ 10^5

Problem C. 但有用 (haji.c/cpp/pas)
Input file: haji.in
Output file: haji.out
Time limit: 1 second
Memory limit: 8 megabytes

給定一個 n ∗ m 個矩陣,矩陣中每個數都是 [1,12] 內的整數。你可以執行下列兩個操作任意多次:
• 指定一行,將該行所有數字 +1.
• 指定一列,將該列所有數字 +1.
如果執行完上述操作之後,矩陣中某個數變成了 3,6,9,12 其中的某一個,我們認爲這個數是穩的。
給定初始矩陣,求出任意執行操作之後穩數的最多個數。

Input
第一行包含兩個正整數 n,m。
接下來 n 行,每行 m 個數,描述這個矩陣。
Output
一個整數,表示答案。

Examples
3 3
1 2 3
3 2 4
1 2 1
7

5 5
2 4 6 8 10
1 2 3 4 5
3 4 5 6 7
7 8 9 10 11
5 10 12 3 7
20

Notes
測試點編號 限制與約束
1 n,m ≤ 2
2 n,m ≤ 5
3,4,5,6,7,8,9,10 n,m ≤ 10

T1
O(n)模擬。
但是不要每次都shahuhu地調用strlen,因爲這個十個點全T。

T2
貪心,每次都輸出不是末尾的最大數字和它後面緊跟的數。
鏈表,記錄後面第一個比它小的數字,模擬。
(數據比較弱,我用一個數組記錄位置也可以過)

T3
可以發現只需加0,1,2這三個數就可以,以爲加3和不加是等價的。
然後,我們暴力枚舉每一行加0或1或2,枚舉完之後,發現每一列是獨立的,貪心看看每一列加幾得到的穩數最多,把每一列得到的最多個數加起來就是答案。
時間複雜度:O(3^n *n*m)

T1

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
using namespace std;
const int N=100009;
char s[N];
int len;
int main()
{
    freopen("nigeru.in","r",stdin);
    freopen("nigeru.out","w",stdout);
    gets(s);len=strlen(s);
    for(int i=0;i<len;i++) if(s[i]<='Z'&&s[i]>='A') s[i]+=32;
    int t=0;
    while(t<len)
    {
        while((s[t]<'a'||s[t]>'z')&&t<len)
        {
            printf("%c",s[t]);
            t++;
        }
        if(t<len){printf("%c",s[t]-32);t++;}
        else break;
        while(((s[t]<='z'&&s[t]>='a')||s[t]==' ')&&t<len) 
        {
            printf("%c",s[t]);
            t++;
        }
    }
    return 0;
}

T2

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
using namespace std;
const int N=100009;
int a[N],n,pos[N],num;
bool vis[N];
int main()
{
    freopen("wa.in","r",stdin);
    freopen("wa.out","w",stdout);
    scanf("%d",&n);num=n/2;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),pos[a[i]]=i;
    int t=n,i;
    for(;num;)
    {
        while(vis[t]||t==a[n]) t--;
        for(i=pos[t]+1;i<=n;i++) if(!vis[a[i]]) break;
        if(i==n+1) 
        {
            t--;
            continue;
        }
        vis[t]=1;
        vis[a[i]]=1;
        printf("%d %d ",t,a[i]);
        num--;
    }
//  printf("\ntime:%d",clock()/1000);
    return 0;
}

T3

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
using namespace std;
int n,m,a[15][15],ans;
void dfs(int x)
{
    if(x==n+1)
    {
        int s=0;
        for(int j=1;j<=m;j++)
        {
            int n0=0,n1=0,n2=0;
            for(int i=1;i<=n;i++)
            {
                if(a[i][j]>12) continue;
                if(a[i][j]%3==0) n0++;
                if(a[i][j]%3==1) n1++;
                if(a[i][j]%3==2) n2++;
            }
            s+=max(n0,max(n1,n2));  
        } 
        ans=max(ans,s);
        return;
    }
    dfs(x+1);//不加 
    for(int t=1;t<=2;t++)
    {
        for(int i=1;i<=m;i++) a[x][i]+=t;
        dfs(x+1);
        for(int i=1;i<=m;i++) a[x][i]-=t;
    }
}
int main()
{
    freopen("haji.in","r",stdin);
    freopen("haji.out","w",stdout); 
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
     for(int j=1;j<=m;j++)
      scanf("%d",&a[i][j]);
    dfs(1);
    printf("%d",ans);
    return 0;
} 
發佈了339 篇原創文章 · 獲贊 240 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章