#46344: C++解 5ms


jusdin6@gmail.com (土撥)

學校 : 國立臺中第一高級中學
編號 : 159631
來源 : [49.215.234.76]
最後登入時間 :
2023-11-08 15:23:24

分三個區塊跟一個主程式

用二維陣列紀錄轉盤

 

#include<bits/stdc++.h>
using namespace std;

int m,n,k,point;
char circle[30][30] = {0};

void turn(int listnum,int turning){
    char teemp[30];
    for(int i = 0;i < n;i++){
        teemp[i] = circle[listnum][turning];
        turning = turning + 1;
        if (turning >= n){
            turning = turning - n;
        }
    }
    for(int i = 0;i < n;i++){
        circle[listnum][i] = teemp[i];
    }
}

int num(int x){
    int y = x;
    if (y >= n){
        y = y % n;
    }
    y = (y - n) * -1;
    if (y >= n){
        y = y % n;
    }
    return y;
}

void count(){
    for(int r = 0;r < n;r++){
        int row = 0;
        for(int i = 0;i < m;i++){
            int qqq = 0;
            for(int j = i;j < m;j++){
                if(circle[i][r] == circle[j][r]){
                    qqq = qqq + 1;
                }
            }
            row = max(qqq ,row);
        }
        point = point + row;
    }
}

int main(){
    cin >> m >> n >> k;
    
    for(int i = 0;i < m;i++){
        for(int j = 0;j < n;j++){
            char temp = 0;
            cin >> temp;
            circle[i][j] = temp;
        }
    }
    
    for(int i = 0;i < k;i++){
        for(int j = 0;j < m;j++){
            int turning = 0;
            cin >> turning;
            turning = num(turning);
            turn(j,turning);
        }
        count();
    }
    cout << point;    
    return 0;
}

#46372: Re: C++解 5ms


ytconch@gmail.com (神奇的海螺)

學校 : 國立清水高級中學
編號 : 307834
來源 : [60.198.74.127]
最後登入時間 :
2025-09-13 20:14:17

分三個區塊跟一個主程式

用二維陣列紀錄轉盤

 

#include
using namespace std;

int m,n,k,point;
char circle[30][30] = {0};

void turn(int listnum,int turning){
    char teemp[30];
    for(int i = 0;i < n;i++){
        teemp[i] = circle[listnum][turning];
        turning = turning + 1;
        if (turning >= n){
            turning = turning - n;
        }
    }
    for(int i = 0;i < n;i++){
        circle[listnum][i] = teemp[i];
    }
}

int num(int x){
    int y = x;
    if (y >= n){
        y = y % n;
    }
    y = (y - n) * -1;
    if (y >= n){
        y = y % n;
    }
    return y;
}

void count(){
    for(int r = 0;r < n;r++){
        int row = 0;
        for(int i = 0;i < m;i++){
            int qqq = 0;
            for(int j = i;j < m;j++){
                if(circle[i][r] == circle[j][r]){
                    qqq = qqq + 1;
                }
            }
            row = max(qqq ,row);
        }
        point = point + row;
    }
}

int main(){
    cin >> m >> n >> k;
    
    for(int i = 0;i < m;i++){
        for(int j = 0;j < n;j++){
            char temp = 0;
            cin >> temp;
            circle[i][j] = temp;
        }
    }
    
    for(int i = 0;i < k;i++){
        for(int j = 0;j < m;j++){
            int turning = 0;
            cin >> turning;
            turning = num(turning);
            turn(j,turning);
        }
        count();
    }
    cout << point;    
    return 0;
}

極度陽春半點庫沒用