工 业 文 化

重工业代码一览

广义的工业文化是工业社会的文化,具有工业化时代的典型特征。
也就是说,广义的工业文化随着社会的进步和时代的更迭迟早会消亡变成历史。
而狭义的工业文化,是在工业化进程中产生的,与工业生产活动紧密联系的文化现象。狭义的工业文化至少可以分为两类。
一类是工业和文化的自然融合,比如:工业设计、工艺美术,因为产品生产的需要自然融合到一起;另一类最先是有了工业技术和产品,随着不断的普及应用,融进了文化的元素,例如,广播、电影、电视等。

所以这地方就放一些写着恶心的重工业代码了。可能最后会成为什么重工业代码坟场

Updated

浏览了一下自己树剖的码,发现每篇行数都在200+上,都挺重工业的,所以250-的就没必要放进来了?

P5380 [THUPC2019]鸭棋

点击折叠代码, 防止大家看了恶心
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>

#define Pair pair< int, int >
#define Make(x, y) make_pair(x, y)
#define X first
#define Y second

using namespace std;

const int SIZE = 15;
int q, cnt;
int xs, xt, ys, yt;
int map[SIZE][SIZE];
bool IsOver;
Pair pos[3]; //两边王的位置
//红方的都以 1 开头, 黑方的都以 2 开头
//兵的下一位是 1
//鸭的下一位是 2
//车的下一位是 3
//马的下一位是 4
//象的下一位是 5
//士的下一位是 6
//王的下一位是 7
void init(){ //棋盘和坐标要转一下
    map[0][0] = 13/*红车*/, map[0][1] = 14/*红马*/, map[0][2] = 15/*红象*/;
    map[0][3] = 16/*红士*/, map[0][4] = 17/*红王*/, map[0][5] = 16/*红士*/;
    map[0][6] = 15/*红象*/, map[0][7] = 14/*红马*/, map[0][8] = 13/*红车*/;
    map[2][0] = 12/*红鸭*/, map[2][8] = 12/*红鸭*/;
    map[3][0] = 11/*红兵*/, map[3][2] = 11/*红兵*/, map[3][4] = 11/*红兵*/, map[3][6] = 11/*红兵*/, map[3][8] = 11/*红兵*/;

    map[6][0] = 21/*蓝兵*/, map[6][2] = 21/*蓝兵*/, map[6][4] = 21/*蓝兵*/, map[6][6] = 21/*蓝兵*/, map[6][8] = 21/*蓝兵*/;
    map[7][0] = 22/*蓝鸭*/, map[7][8] = 22/*蓝鸭*/;
    map[9][0] = 23/*蓝车*/, map[9][1] = 24/*蓝马*/, map[9][2] = 25/*蓝象*/;
    map[9][3] = 26/*蓝士*/, map[9][4] = 27/*蓝王*/, map[9][5] = 26/*蓝士*/;
    map[9][6] = 25/*蓝象*/, map[9][7] = 24/*蓝马*/, map[9][8] = 23/*蓝车*/;

    pos[1] = Make(0, 4);
    pos[2] = Make(9, 4);
}

bool Have_Piece(int x, int y){
    if(!map[x][y]) return false;
    else return true;
}

string Get_Color(int num){
    if(num == 1) return "red";
    else return "blue";
}

string Get_Type(int num){
    switch(num){
        case 1 : return "soldier";
        case 2 : return "duck";
        case 3 : return "car";
        case 4 : return "horse";
        case 5 : return "elephant";
        case 6 : return "guard";
        case 7 : return "captain";
    }
}

bool Check_Soldier(int cols, int xs, int ys, int xt, int yt){ //兵一共就八个位置能走,一一枚举就行
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int d[8][8] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

    for(register int i = 0; i < 8 && !IsCanMove; i++){
        int nowx = xs + d[i][0], nowy = ys + d[i][1];
        if(nowx == xt && nowy == yt && colt != cols) IsCanMove = true;
    }
    if(!IsCanMove) return cout << "Invalid command" << "\n", false;

    map[xs][ys] = 0;
    map[xt][yt] = cols * 10 + 1;

    if(colt == 0) cout << Get_Color(cols) << " soldier;" << "NA;";
    else{
        if(typet == 7) pos[colt] = Make(-1, -1);
        cout << Get_Color(cols) << " soldier;" << Get_Color(colt) << " " << Get_Type(typet) << ";";
    }

    return true;
}

bool Check_Duck(int cols, int xs, int ys, int xt, int yt){
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int s[4][4] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

    for(register int i = 0; i < 4 && !IsCanMove; i++){
        int x1 = xs + s[i][0] * 2, y1 = ys + s[i][1];
        int x2 = xs + s[i][0], y2 = ys;
        int nowx = xs + s[i][0] * 3, nowy = ys + s[i][1] * 2;
        if(map[x1][y1] == 0 && map[x2][y2] == 0 && nowx == xt && nowy == yt && colt != cols) IsCanMove = true;

        x1 = xs + s[i][0], y1 = ys + s[i][1] * 2;
        x2 = xs, y2 = ys + s[i][1];
        nowx = xs + s[i][0] * 2, nowy = ys + s[i][1] * 3;
        if(map[x1][y1] == 0 && map[x2][y2] == 0 && nowx == xt && nowy == yt && colt != cols) IsCanMove = true;
    }
    if(!IsCanMove) return cout << "Invalid command" << "\n", false;

    map[xs][ys] = 0;
    map[xt][yt] = cols * 10 + 2;

    if(colt == 0) cout << Get_Color(cols) << " duck;" << "NA;";
    else{
        if(typet == 7) pos[colt] = Make(-1, -1);
        cout << Get_Color(cols) << " duck;" << Get_Color(colt) << " " << Get_Type(typet) << ";";
    }

    return true;
}

bool Check_Car(int cols, int xs, int ys, int xt, int yt){
    if(xs != xt && ys != yt) return cout << "Invalid command" << "\n", false;
    if(xs == xt)
        for(register int i = min(ys, yt) + 1; i < max(ys, yt); i++)
            if(map[xs][i] != 0) return cout << "Invalid command" << "\n", false;
    if(ys == yt)
        for(register int i = min(xs, xt) + 1; i < max(xs, xt); i++)
            if(map[i][ys] != 0) return cout << "Invalid command" << "\n", false;
        
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    if(colt == cols) return cout << "Invalid command" << "\n", false;

    map[xs][ys] = 0;
    map[xt][yt] = cols * 10 + 3;

    if(colt == 0) cout << Get_Color(cols) << " car;" << "NA;";
    else{
        if(typet == 7) pos[colt] = Make(-1, -1);
        cout << Get_Color(cols) << " car;" << Get_Color(colt) << " " << Get_Type(typet) << ";";
    }

    return true;
}

bool Check_Horse(int cols, int xs, int ys, int xt, int yt){
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int s[4][4] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

    for(register int i = 0; i < 4 && !IsCanMove; i++){
        int tmpx = xs + s[i][0], tmpy = ys;
        int nowx = xs + s[i][0] * 2, nowy = ys + s[i][1];
        if(nowx == xt && nowy == yt && map[tmpx][tmpy] == 0 && colt != cols) IsCanMove = true;

        tmpx = xs, tmpy = ys + s[i][1];
        nowx = xs + s[i][0], nowy = ys + s[i][1] * 2;
        if(nowx == xt && nowy == yt && map[tmpx][tmpy] == 0 && colt != cols) IsCanMove = true;
    }
    if(!IsCanMove) return cout << "Invalid command" << "\n", false;

    map[xs][ys] = 0;
    map[xt][yt] = cols * 10 + 4;

    if(colt == 0) cout << Get_Color(cols) << " horse;" << "NA;";
    else{
        if(typet == 7) pos[colt] = Make(-1, -1);
        cout << Get_Color(cols) << " horse;" << Get_Color(colt) << " " << Get_Type(typet) << ";";
    }

    return true;
}

bool Check_Elephant(int cols, int xs, int ys, int xt, int yt){
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int s[4][4] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

    for(register int i = 0; i < 4 && !IsCanMove; i++){
        int tmpx = xs + s[i][0], tmpy = ys + s[i][1];
        int nowx = xs + s[i][0] * 2, nowy = ys + s[i][1] * 2;
        if(nowx == xt && nowy == yt && map[tmpx][tmpy] == 0 && colt != cols) IsCanMove = true;
    }
    if(!IsCanMove) return cout << "Invalid command" << "\n", false;

    map[xs][ys] = 0;
    map[xt][yt] = cols * 10 + 5;

    if(colt == 0) cout << Get_Color(cols) << " elephant;" << "NA;";
    else{
        if(typet == 7) pos[colt] = Make(-1, -1);
        cout << Get_Color(cols) << " elephant;" << Get_Color(colt) << " " << Get_Type(typet) << ";";
    }

    return true;
}

bool Check_Guard(int cols, int xs, int ys, int xt, int yt){
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int d[4][4] = {{1, 1}, {1, -1}, {-1, -1}, {-1, 1}};

    for(register int i = 0; i < 4 && !IsCanMove; i++){
        int nowx = xs + d[i][0], nowy = ys + d[i][1];
        if(nowx == xt && nowy == yt && colt != cols) IsCanMove = true;
    }
    if(!IsCanMove) return cout << "Invalid command" << "\n", false;

    map[xs][ys] = 0;
    map[xt][yt] = cols * 10 + 6;

    if(colt == 0) cout << Get_Color(cols) << " guard;" << "NA;";
    else{
        if(typet == 7) pos[colt] = Make(-1, -1);
        cout << Get_Color(cols) << " guard;" << Get_Color(colt) << " " << Get_Type(typet) << ";";
    }

    return true;
}

bool Check_Captain(int cols, int xs, int ys, int xt, int yt){
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int d[4][4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

    for(register int i = 0; i < 4 && !IsCanMove; i++){
        int nowx = xs + d[i][0], nowy = ys + d[i][1];
        if(nowx == xt && nowy == yt && colt != cols) IsCanMove = true;
    }
    if(!IsCanMove) return cout << "Invalid command" << "\n", false;

    map[xs][ys] = 0;
    map[xt][yt] = cols * 10 + 7;
    pos[cols] = Make(xt, yt);

    if(colt == 0) cout << Get_Color(cols) << " captain;" << "NA;";
    else{
        if(typet == 7) pos[colt] = Make(-1, -1);
        cout << Get_Color(cols) << " captain;" << Get_Color(colt) << " " << Get_Type(typet) << ";";
    }

    return true;
}

bool Move(int col, int type, int xs, int ys, int xt, int yt){
    switch(type){
        case 1 : return Check_Soldier(col, xs, ys, xt, yt);
        case 2 : return Check_Duck(col, xs, ys, xt, yt);
        case 3 : return Check_Car(col, xs, ys, xt, yt);
        case 4 : return Check_Horse(col, xs, ys, xt, yt);
        case 5 : return Check_Elephant(col, xs, ys, xt, yt);
        case 6 : return Check_Guard(col, xs, ys, xt, yt);
        case 7 : return Check_Captain(col, xs, ys, xt, yt);
    }
}

bool Mate_Soldier(int cols, int xs, int ys, int xt, int yt){
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int d[8][8] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

    for(register int i = 0; i < 8 && !IsCanMove; i++){
        int nowx = xs + d[i][0], nowy = ys + d[i][1];
        if(nowx == xt && nowy == yt && colt != cols) IsCanMove = true;
    }

    return IsCanMove;
}

bool Mate_Duck(int cols, int xs, int ys, int xt, int yt){
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int s[4][4] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

    for(register int i = 0; i < 4 && !IsCanMove; i++){
        int x1 = xs + s[i][0] * 2, y1 = ys + s[i][1];
        int x2 = xs + s[i][0], y2 = ys;
        int nowx = xs + s[i][0] * 3, nowy = ys + s[i][1] * 2;
        if(map[x1][y1] == 0 && map[x2][y2] == 0 && nowx == xt && nowy == yt && colt != cols) IsCanMove = true;

        x1 = xs + s[i][0], y1 = ys + s[i][1] * 2;
        x2 = xs, y2 = ys + s[i][1];
        nowx = xs + s[i][0] * 2, nowy = ys + s[i][1] * 3;
        if(map[x1][y1] == 0 && map[x2][y2] == 0 && nowx == xt && nowy == yt && colt != cols) IsCanMove = true;
    }
    
    return IsCanMove;
}

bool Mate_Car(int cols, int xs, int ys, int xt, int yt){
    if(xs != xt && ys != yt) return false;
    if(xs == xt)
        for(register int i = min(ys, yt) + 1; i < max(ys, yt); i++)
            if(map[xs][i] != 0) return false;
    if(ys == yt)
        for(register int i = min(xs, xt) + 1; i < max(xs, xt); i++)
            if(map[i][ys] != 0) return false;
        
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    if(colt == cols) return false;

    return true;
}

bool Mate_Horse(int cols, int xs, int ys, int xt, int yt){
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int s[4][4] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

    for(register int i = 0; i < 4 && !IsCanMove; i++){
        int tmpx = xs + s[i][0], tmpy = ys;
        int nowx = xs + s[i][0] * 2, nowy = ys + s[i][1];
        if(nowx == xt && nowy == yt && map[tmpx][tmpy] == 0 && colt != cols) IsCanMove = true;

        tmpx = xs, tmpy = ys + s[i][1];
        nowx = xs + s[i][0], nowy = ys + s[i][1] * 2;
        if(nowx == xt && nowy == yt && map[tmpx][tmpy] == 0 && colt != cols) IsCanMove = true;
    }
    
    return IsCanMove;
}

bool Mate_Elephant(int cols, int xs, int ys, int xt, int yt){
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int s[4][4] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

    for(register int i = 0; i < 4 && !IsCanMove; i++){
        int tmpx = xs + s[i][0], tmpy = ys + s[i][1];
        int nowx = xs + s[i][0] * 2, nowy = ys + s[i][1] * 2;
        if(nowx == xt && nowy == yt && map[tmpx][tmpy] == 0 && colt != cols) IsCanMove = true;
    }
    
    return IsCanMove;
}

bool Mate_Guard(int cols, int xs, int ys, int xt, int yt){
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int d[4][4] = {{1, 1}, {1, -1}, {-1, -1}, {-1, 1}};

    for(register int i = 0; i < 4 && !IsCanMove; i++){
        int nowx = xs + d[i][0], nowy = ys + d[i][1];
        if(nowx == xt && nowy == yt && colt != cols) IsCanMove = true;
    }
    
    return IsCanMove;
}

bool Mate_Captain(int cols, int xs, int ys, int xt, int yt){
    bool IsCanMove = false;
    int colt = map[xt][yt] / 10, typet = map[xt][yt] % 10;
    const int d[4][4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

    for(register int i = 0; i < 4 && !IsCanMove; i++){
        int nowx = xs + d[i][0], nowy = ys + d[i][1];
        if(nowx == xt && nowy == yt && colt != cols) IsCanMove = true;
    }
    
    return IsCanMove;
}

bool Mate(int col, int type, int xs, int ys, int xt, int yt){
    switch(type){
        case 1 : return Mate_Soldier(col, xs, ys, xt, yt);
        case 2 : return Mate_Duck(col, xs, ys, xt, yt);
        case 3 : return Mate_Car(col, xs, ys, xt, yt);
        case 4 : return Mate_Horse(col, xs, ys, xt, yt);
        case 5 : return Mate_Elephant(col, xs, ys, xt, yt);
        case 6 : return Mate_Guard(col, xs, ys, xt, yt);
        case 7 : return Mate_Captain(col, xs, ys, xt, yt);
    }
}

bool Checkmate(int col){
    bool IsCheckmate = false;
    Pair p = pos[col];
    int xpos = p.X, ypos = p.Y;

    for(register int i = 0; i < 10 && !IsCheckmate; i++){
        for(register int j = 0; j < 9 && !IsCheckmate; j++){
            int color = map[i][j] / 10, type = map[i][j] % 10;
            if(color == 0 || color == col) continue;
            IsCheckmate = Mate(color, type, i, j, xpos, ypos);
        }
    }

    return IsCheckmate;
}

bool Game_Over(){
    Pair p = Make(-1, -1);
    if(pos[1] == p || pos[2] == p) return true;
    else return false;
}

int main(){
    ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

    init();

    cin >> q, cnt = 1;
    for(register int i = 1; i <= q; i++){
        cin >> xs >> ys >> xt >> yt;
        
        if(IsOver){
            cout << "Invalid command" << "\n";
            continue;
        }
        if(xs < 0 || xs > 9 || ys < 0 || ys > 8 || xt < 0 || xt > 9 || yt < 0 || yt > 8){
            cout << "Invalid command" << "\n";
            continue;
        }
        if(!Have_Piece(xs, ys)){
            cout << "Invalid command" << "\n";
            continue;
        }

        int color = map[xs][ys] / 10;
        int type = map[xs][ys] % 10;
        if((cnt & 1) && color != 1){
            cout << "Invalid command" << "\n";
            continue;
        }
        if(!(cnt & 1) && color != 2){
            cout << "Invalid command" << "\n";
            continue;
        }

        if(!Move(color, type, xs, ys, xt, yt)) continue;
        ++cnt;
        if(Checkmate(1) || Checkmate(2)) cout << "yes;";
        else cout << "no;";
        if(Game_Over()){
            cout << "yes" << "\n";
            IsOver = true;
        }
        else cout << "no" << "\n";
    }
    
    return 0;
}

P7506 「Wdsr-2.5」琪露诺的算数游戏

点击折叠代码, 防止大家看了恶心
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

const int MAXN = 35, MAXM = 110, MAXK = 3e5 + 10;
const int INF = 2147483647;
const string Card_Nomal[18] = {"C2", "A99", "A49", "A19", "A9", "A5", "A2", "A1", "B1", "B9", "B19", "D2", "E99", "E49", "E0", "PASS", "TURN", "DOUBLE"};
const string Card_Double[18] = {"PASS", "TURN", "DOUBLE", "D2", "B19", "B9", "B1", "A1", "A2", "A5", "A9", "A19", "A49", "A99", "C2", "E0", "E49", "E99"};
int n, m, k, p, st/*起始玩家*/, top/*牌堆顶*/;
string card_heap[MAXK]; //牌堆
bool turn; //出牌顺序 
bool IsDouble[MAXN]; //玩家的身上有没有 DOUBLE 标记

struct Player{
    string name;
    string card[4];
}pl[MAXN];

int Find_Nomal(string s){
    for(register int i = 0; i < 18; i++)
        if(Card_Nomal[i] == s) return i;
    
    puts("Wrang spelling! Fuck you!");  
    return 114514;
}

int Find_Double(string s){
    for(register int i = 0; i < 18; i++)
        if(Card_Double[i] == s) return i;
    
    puts("Wrang spelling! Fuck you!"); 
    return 114514;
}

bool cmp_nomal(string s1, string s2){
    return Find_Nomal(s1) < Find_Nomal(s2);
}

bool cmp_double(string s1, string s2){
    return Find_Double(s1) < Find_Double(s2);
}

void Send_Card(int pos, int sit){ //发牌 
    pl[pos].card[sit] = card_heap[top];
    top++;
}

void Fail(int pos){ //第 pos 个人失败了 
    cout << pl[pos].name << " " << "lost the game." << endl;

    st = pos; //下一轮从 pos 开始
    Send_Card(pos, 1); //清空他的手牌,从牌堆抽三张牌
    Send_Card(pos, 2);
    Send_Card(pos, 3);
}

int Get_Number(string s){
    int num;
    int len = s.size();

    if(len == 2)
        num = s[1] - '0';
    else if(len == 3)
        num = (s[1] - '0') * 10 + (s[2] - '0');
    
    return num;
}

int Modify_Nomal(int type){ //查询 p 会被变成什么
    int num;

    switch(type){
        case 0: num = p * 2; break;
        case 1: num = p + 99; break;
        case 2: num = p + 49; break;
        case 3: num = p + 19; break;
        case 4: num = p + 9; break;
        case 5: num = p + 5; break;
        case 6: num = p + 2; break;
        case 7: num = p + 1; break;
        case 8: num = p - 1; break;
        case 9: num = p - 9; break;
        case 10: num = p - 19; break;
        case 11: num = (p >> 1); break;
        case 12: num = 99; break;
        case 13: num = 49; break;
        case 14: num = 0; break;
        case 15: num = 114514; break;
        case 16: num = 1919810; break;
        case 17: num = 1433223; break;
    }

    return num;
}

bool Play_Nomal(int pos){ //没有被 DOUBLE 标记的出牌阶段  
    int max_p = -INF/*p 能达到的最大值*/, type/*选择的牌型*/, sit/*出牌的位置*/, out;

    sort(pl[pos].card + 1, pl[pos].card + 1 + 3, cmp_nomal); //按照一般情况进行排序 
    for(register int i = 1; i <= 3; i++){
        int opt = Find_Nomal(pl[pos].card[i]); //当前手牌的牌型 
        int now_p = Modify_Nomal(opt);
        int num = Get_Number(pl[pos].card[i]);

        if(now_p == 114514 || now_p == 1919810 || now_p == 1433223){
            if(max_p == -INF){ //如果普通牌解不了 
                if(now_p == 114514){ //使用了PASS 
                    cout << pl[pos].name << " " << "used" << " " << "PASS,now p=" << p << "." << endl;

                    Send_Card(pos, i); //打出牌后,再抽取一张手牌 

                    return 1;
                }
                else if(now_p == 1919810){ //使用了TURN
                    cout << pl[pos].name << " " << "used" << " " << "TURN,now p=" << p << "." << endl;

                    turn = !turn; //出牌顺序取反 
                    Send_Card(pos, i);

                    return 1;
                }
                else if(now_p == 1433223){ //使用了double
                    cout << pl[pos].name << " " << "used" << " " << "DOUBLE,now p=" << p << "." << endl;

                    if(turn){ //顺序出牌
                        if(pos + 1 <= n) IsDouble[pos + 1] = true;
                        else IsDouble[1] = true;
                        //下家被打上标记
                    }
                    else{ //逆序出牌
                        if(pos - 1 >= 1) IsDouble[pos - 1] = true;
                        else IsDouble[n] = true;
                        //下家被打上标记 
                    }
                    
                    Send_Card(pos, i);

                    return 1;
                }
            }
        }

        if(now_p > max_p && now_p <= 99){
            max_p = now_p;
            type = opt;
            out = num;
            sit = i;
        }
    }

    if(max_p == -INF) //没有找到任意一种可以赢的方案
        return 0;
    else{ //可以过  
        p = max_p; //p改变
        cout << pl[pos].name << " " << "used" << " ";

        if(type == 0) cout << "C";
        else if(type >= 1 && type <= 7) cout << "A";
        else if(type >= 8 && type <= 10) cout <<"B";
        else if(type == 11) cout << "D";
        else cout << "E";

        cout << out <<",now p=" << p << "." << endl;

        Send_Card(pos, sit); //再抽一张牌 

        return 1; 
    }
}

int Modify_Double(int type){
    int num;

    switch(type){
        case 0: num = 114514; break;
        case 1: num = 1919810; break;
        case 2: num = 1433223; break;
        case 3: num = (p >> 1); break;
        case 4: num = p - 19; break;
        case 5: num = p - 9; break;
        case 6: num = p - 1; break;
        case 7: num = p + 1; break;
        case 8: num = p + 2; break;
        case 9: num = p + 5; break;
        case 10: num = p + 9; break;
        case 11: num = p + 19; break;
        case 12: num = p + 49; break;
        case 13: num = p + 99; break;
        case 14: num = p * 2; break;
        case 15: num = 0; break;
        case 16: num = 49; break;
        case 17: num = 99; break;
    }

    return num;
}

bool Play_Double(int pos){ ////被 DOUBLE 标记的出牌阶段
    int min_p = INF/*p 能达到的最小值*/, type/*选择的牌型*/, sit/*出牌的位置*/, out; 

    sort(pl[pos].card + 1, pl[pos].card + 1 + 3, cmp_double);
    for(register int i = 1; i <= 3; i++){
        int opt = Find_Double(pl[pos].card[i]); //当前手牌的牌型 
        int now_p = Modify_Double(opt);
        int num = Get_Number(pl[pos].card[i]);

        if(now_p == 114514 || now_p == 1919810 || now_p == 1433223){
            if(now_p == 114514){
                cout << pl[pos].name << " " << "used" << " " << "PASS,now p=" << p << "." << endl;
                IsDouble[pos] = false; //标记消除
                if(turn){ //顺序出牌
                    if(pos + 1 <= n) IsDouble[pos + 1] = true;
                    else IsDouble[1] = true;
                    //下家被打上标记
                }
                else{ //逆序出牌
                    if(pos - 1 >= 1) IsDouble[pos - 1] = true;
                    else IsDouble[n] = true;
                    //下家被打上标记 
                }

                Send_Card(pos, i); //打出牌后,再抽取一张手牌 

                return 1;
            }
                        
            else if(now_p == 1919810){
                cout << pl[pos].name << " " << "used" << " " << "TURN,now p=" << p << "." << endl;
                turn = !turn; //出牌顺序取反 
                IsDouble[pos] = false; //标记消除
                if(turn){ //顺序出牌
                    if(pos + 1 <= n) IsDouble[pos + 1] = true;
                    else IsDouble[1] = true;
                    //下家被打上标记
                }
                else{ //逆序出牌
                    if(pos - 1 >= 1) IsDouble[pos - 1] = true;
                    else IsDouble[n] = true;
                    //下家被打上标记 
                }

                Send_Card(pos, i);

                return 1;
            }

            else if(now_p == 1433223){
                cout << pl[pos].name << " " << "used" << " " << "DOUBLE,now p=" << p << "." << endl;
                IsDouble[pos] = false; //标记消除
                if(turn){ //顺序出牌
                    if(pos + 1 <= n) IsDouble[pos + 1] = true;
                    else IsDouble[1] = true;
                    //下家被打上标记
                }
                else{ //逆序出牌
                    if(pos - 1 >= 1) IsDouble[pos - 1] = true;
                    else IsDouble[n] = true;
                    //下家被打上标记 
                }

                Send_Card(pos, i); //打出牌后,再抽取一张手牌 

                return 1;
            }
        }

        if(now_p < min_p && now_p <= 99){
            min_p = now_p;
            type = opt;
            out = num;
            sit = i;
        }
    }

    if(min_p == INF)
        return 0;
        
    else{
        p = min_p;
        IsDouble[pos] = false; //标记消除 
        cout << pl[pos].name << " " << "used" << " ";

        if(type == 3) cout << "D";
        else if(type >= 4 && type <= 6) cout << "B";
        else if(type >= 7 && type <= 13) cout << "A";
        else if(type == 14) cout << "C";
        else cout << "E";

        cout << out <<",now p=" << p << "." << endl;

        Send_Card(pos, sit);

        bool Iswin = Play_Nomal(pos);

        if(Iswin) return 1;
        else return 0;
    }
}

bool Pass_Card(int pos){ //轮到第 pos 个人出牌了 
    bool Ispass = false; //标记这个人能不能通过本轮 

    if(!IsDouble[pos]) //没有被标记 
        Ispass = Play_Nomal(pos);
    else
        Ispass = Play_Double(pos);

    return Ispass;
}

void Solve_Round(int num){ //第 num 局
    cout << "Round" << " " << num << ":" << endl;

    p = 0;
    int now = st;
    turn = true; //表示顺序开牌还是逆序开牌    
    memset(IsDouble, 0, sizeof(IsDouble)); //新开一轮每名玩家的标记要清空 

    while(1){
        if(now > n) now = 1;
        if(now < 1) now = n;

        if(!Pass_Card(now)){
            Fail(now);
            break;
        }

        if(turn) now++;
        else now--;
    }
}

int main(){
    ios::sync_with_stdio(false);

    cin >> n >> m >> k;
    for(register int i = 1; i <= n; i++){
        string s1, s2, s3, s4;
        cin >> s1 >> s2 >> s3 >> s4;

        pl[i].name = s1;
        pl[i].card[1] = s2;
        pl[i].card[2] = s3;
        pl[i].card[3] = s4;
    }
    for(register int i = 1; i <= k; i++)
        cin >> card_heap[i];
    
    
    st = 1;
    top = 1;
    for(register int i = 1; i <= m; i++)
        Solve_Round(i);
    
    return 0;
}

P1505 [国家集训队]旅游

点击折叠代码, 防止大家看了恶心
#include<cstdio>
#include<algorithm>

using namespace std;

const int MAXN = 2e5 + 10;
const int INF = 2147483647;
int n, m, cnt, num;
int head[MAXN], from[MAXN], to[MAXN];
int dis[MAXN], val[MAXN];
int fa[MAXN], son[MAXN], size[MAXN], deep[MAXN];
int top[MAXN], dfn[MAXN];

struct Edge{
    int to, next, dis;
}e[MAXN << 1];

inline void Add(int u, int v, int w){
    e[++cnt].to = v;
    e[cnt].dis = w;
    e[cnt].next = head[u];
    head[u] = cnt;
}

void dfs_deep(int rt, int father, int depth){
    size[rt] = 1;
    fa[rt] = father;
    deep[rt] = depth;

    int max_son = -1;
    for(register int i = head[rt]; i; i = e[i].next){
        int v = e[i].to;
        if(v == father) continue;

        dis[v] = e[i].dis;
        dfs_deep(v, rt, depth + 1);
        size[rt] += size[v];

        if(max_son < size[v]){
            son[rt] = v;
            max_son = size[v];
        }
    }
}

void dfs_top(int rt, int top_fa){
    dfn[rt] = ++num;
    top[rt] = top_fa;
    val[num] = dis[rt];

    if(!son[rt]) return;
    dfs_top(son[rt], top_fa);

    for(register int i = head[rt]; i; i = e[i].next){
        int v = e[i].to;
        if(!dfn[v]) dfs_top(v, v);
    }
}

struct Segment_Tree{
    struct Tree{
        int l, r;
        int sum, max, min;
        int lazy;
    }tr[MAXN << 2];

    inline int lson(int rt){
        return rt << 1;
    }

    inline int rson(int rt){
        return rt << 1 | 1;
    }

    inline void Pushup(int rt){
        tr[rt].sum = tr[lson(rt)].sum + tr[rson(rt)].sum;
        tr[rt].max = max(tr[lson(rt)].max, tr[rson(rt)].max);
        tr[rt].min = min(tr[lson(rt)].min, tr[rson(rt)].min);
    }

    inline void Pushdown(int rt){
        if(tr[rt].lazy){
            tr[lson(rt)].lazy ^= 1;
            tr[rson(rt)].lazy ^= 1;

            tr[lson(rt)].sum = -tr[lson(rt)].sum;
            tr[lson(rt)].max = -tr[lson(rt)].max;
            tr[lson(rt)].min = -tr[lson(rt)].min;
            swap(tr[lson(rt)].max, tr[lson(rt)].min);

            tr[rson(rt)].sum = -tr[rson(rt)].sum;
            tr[rson(rt)].max = -tr[rson(rt)].max;
            tr[rson(rt)].min = -tr[rson(rt)].min;
            swap(tr[rson(rt)].max, tr[rson(rt)].min);

            tr[rt].lazy = 0;
        }
    }

    void Build(int rt, int l, int r){
        tr[rt].l = l;
        tr[rt].r = r;

        if(l == r){
            tr[rt].sum = tr[rt].max = tr[rt].min = val[l];
            return;
        }

        int mid = (l + r) >> 1;
        Build(lson(rt), l, mid);
        Build(rson(rt), mid + 1, r);

        Pushup(rt);
    }

    void Update(int rt, int pos, int data){
        if(tr[rt].l == tr[rt].r){
            tr[rt].sum = tr[rt].max = tr[rt].min = data;
            return;
        }

        Pushdown(rt);

        int mid = (tr[rt].l + tr[rt].r) >> 1;
        if(pos <= mid) Update(lson(rt), pos, data);
        else Update(rson(rt), pos, data);

        Pushup(rt);
    }

    void Change(int rt, int l, int r){
        if(tr[rt].l >= l && tr[rt].r <= r){
            tr[rt].sum = -tr[rt].sum;
            tr[rt].max = -tr[rt].max;
            tr[rt].min = -tr[rt].min;
            tr[rt].lazy ^= 1;
            swap(tr[rt].max, tr[rt].min);

            return;
        }

        Pushdown(rt);

        int mid = (tr[rt].l + tr[rt].r) >> 1;
        if(l <= mid) Change(lson(rt), l, r);
        if(r > mid) Change(rson(rt), l, r);

        Pushup(rt);
    }

    int Query_Sum(int rt, int l, int r){
        if(tr[rt].l >= l && tr[rt].r <= r)
            return tr[rt].sum;
        
        Pushdown(rt);

        int ans = 0;
        int mid = (tr[rt].l + tr[rt].r) >> 1;
        if(l <= mid) ans += Query_Sum(lson(rt), l, r);
        if(r > mid) ans += Query_Sum(rson(rt), l, r);
        
        Pushup(rt);

        return ans;
    }

    int Query_Max(int rt, int l, int r){
        if(tr[rt].l >= l && tr[rt].r <= r)
            return tr[rt].max;
        
        Pushdown(rt);

        int ans = -INF;
        int mid = (tr[rt].l + tr[rt].r) >> 1;
        if(l <= mid) ans = max(ans, Query_Max(lson(rt), l, r));
        if(r > mid) ans = max(ans, Query_Max(rson(rt), l, r));
        
        Pushup(rt);

        return ans;
    }

    int Query_Min(int rt, int l, int r){
        if(tr[rt].l >= l && tr[rt].r <= r)
            return tr[rt].min;
        
        Pushdown(rt);

        int ans = INF;
        int mid = (tr[rt].l + tr[rt].r) >> 1;
        if(l <= mid) ans = min(ans, Query_Min(lson(rt), l, r));
        if(r > mid) ans = min(ans, Query_Min(rson(rt), l, r));
        
        Pushup(rt);

        return ans;
    }
}S;

void Change_Tree(int x, int y){
    while(top[x] != top[y]){
        if(deep[top[x]] < deep[top[y]]) swap(x, y);
        S.Change(1, dfn[top[x]], dfn[x]);
        x = fa[top[x]];
    }

    if(deep[x] > deep[y]) swap(x, y);
    if(x != y)
        S.Change(1, dfn[x] + 1, dfn[y]);
}

int Query_Sum_Tree(int x, int y){
    int ans = 0;

    while(top[x] != top[y]){
        if(deep[top[x]] < deep[top[y]]) swap(x, y);
        ans += S.Query_Sum(1, dfn[top[x]], dfn[x]);
        x = fa[top[x]];
    }

    if(deep[x] > deep[y]) swap(x, y);
    if(x != y)
        ans += S.Query_Sum(1, dfn[x] + 1, dfn[y]);

    return ans;
}

int Query_Max_Tree(int x, int y){
    int ans = -INF;

    while(top[x] != top[y]){
        if(deep[top[x]] < deep[top[y]]) swap(x, y);
        ans = max(ans, S.Query_Max(1, dfn[top[x]], dfn[x]));
        x = fa[top[x]];
    }

    if(deep[x] > deep[y]) swap(x, y);
    if(x != y)
        ans = max(ans, S.Query_Max(1, dfn[x] + 1, dfn[y]));

    return ans;
}

int Query_Min_Tree(int x, int y){
    int ans = INF;

    while(top[x] != top[y]){
        if(deep[top[x]] < deep[top[y]]) swap(x, y);
        ans = min(ans, S.Query_Min(1, dfn[top[x]], dfn[x]));
        x = fa[top[x]];
    }

    if(deep[x] > deep[y]) swap(x, y);
    if(x != y)
        ans = min(ans, S.Query_Min(1, dfn[x] + 1, dfn[y]));

    return ans;
}

inline int read(){
    int x = 0, f = 1;
    char c = getchar();

    while(c < '0' || c > '9'){
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }

    return x * f;
}

int main(){
    n = read();
    for(register int i = 1; i <= n - 1; i++){
        int u, v, w;
        u = read() + 1, v = read() + 1, w = read();
        Add(u, v, w);
        Add(v, u, w);
        from[i] = u, to[i] = v;
    }

    dfs_deep(1, 0, 1);
    dfs_top(1, 1);
    S.Build(1, 1, n);

    m = read();
    for(register int i = 1; i <= m; i++){
        char opt[5];
        scanf("%s", opt + 1);

        if(opt[1] == 'C'){
            int x, w, u, v;
            x = read(), w = read();
            u = from[x], v = to[x];

            if(deep[u] < deep[v]) swap(u, v); 
            S.Update(1, dfn[u], w);
        }
        else if(opt[1] == 'N'){
            int x, y;
            x = read() + 1, y = read() + 1;
            Change_Tree(x, y);
        }
        else if(opt[1] == 'S'){
            int x, y;
            x = read() + 1, y = read() + 1;
            printf("%d\n", Query_Sum_Tree(x, y));
        }
        else if(opt[1] == 'M' && opt[2] == 'A'){
            int x, y;
            x = read() + 1, y = read() + 1;
            printf("%d\n", Query_Max_Tree(x, y));
        }
        else if(opt[1] == 'M' && opt[2] == 'I'){
            int x, y;
            x = read() + 1, y = read() + 1;
            printf("%d\n", Query_Min_Tree(x, y));
        }
    }

    return 0;
}

P7075 [CSP-S2020] 儒略日

点击折叠代码, 防止大家看了恶心
#include<cstdio>
#include<algorithm>

#define LL long long
#define Pair pair< int, int >
#define Make(x, y) make_pair(x, y);

using namespace std;

const int PMonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int RMonth[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int Pyear = 365, Ryear = 366;
const int STR = 4713, STG = 1582, AD = 1, REST = 1600;
LL q, r;

inline LL read(){
    LL x = 0, f = 1;
    char c = getchar();

    while(c < '0' || c > '9'){
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }

    return x * f;
}

bool BC(LL num){
    return num <= 1LL * Ryear * 1178 + Pyear * 3535;
}

bool Cut_Year_BC(LL &num, int &sum){ //公元前全部使用儒略历,儒略历的
    if(num >= Ryear) num -= Ryear, ++sum; //儒略历的第一年润年

    LL cnt = num / (Pyear * 3 + Ryear);
    num -= 1LL * cnt * (Pyear * 3 + Ryear);
    sum += cnt * 4;

    int tot = 0; //之后又过了几年
    while(num > Pyear){ //最后经过了一个闰年,接下来三个都是平年,最多减去这三个平年
        num -= Pyear;
        ++tot;
    }
    if(num == Ryear) num -= Ryear, ++sum; 
    sum += tot;

    if((tot == 3 && num != 0) || sum == 0)
        return true;
    else return false;
}

Pair Cut_Month_R(LL num, int &sum){
    for(register int i = 1; i <= 12; i++){
        if(num < RMonth[i]) return Make(i, num + 1);
        num -= RMonth[i];
    }
    if(num == 0) ++sum;
    return Make(1, 1);
}

Pair Cut_Month_P(LL num, int &sum){
    for(register int i = 1; i <= 12; i++){
        if(num < PMonth[i]) return Make(i, num + 1);
        num -= PMonth[i];
    }
    if(num == 0) ++sum;
    return Make(1, 1);
}

void Solve_BC(LL &num){
    int sum = 0, year, month, day;

    if(Cut_Year_BC(num, sum)){ //最后停在了闰年
        Pair p = Cut_Month_R(num, sum);
        year = STR - sum;
        month = p.first;
        day = p.second;
    }
    else{
        Pair p = Cut_Month_P(num, sum);
        year = STR - sum;
        month = p.first;
        day = p.second;
    }

    printf("%d %d %d BC\n", day, month, year);
}

bool Gregorian(LL num){ //判断是不是在格里高利历使用前
    return num <= 1LL * 395 * Ryear + 1186 * Pyear + 276;
}

bool Cut_Year_RL(LL &num, int &sum){
    LL cnt = num / (Pyear * 3 + Ryear);
    num -= cnt * (Pyear * 3 + Ryear);
    sum += cnt * 4; 

    int tot = 0; //之后又过了几年
    while(num > Pyear){ //最后经过了一个闰年,接下来三个都是平年,最多减去这三个平年
        num -= Pyear;
        ++tot;
    }
    if(num == Ryear) num -= Ryear, ++sum; 
    sum += tot;

    if(tot == 3 && num != 0)
        return true;
    else return false;
}

void Solve_RL(LL &num){
    int sum = 0, year, month, day;

    if(Cut_Year_RL(num, sum)){
        Pair p = Cut_Month_R(num, sum);
        year = AD + sum;
        month = p.first;
        day = p.second;
    }
    else{
        Pair p = Cut_Month_P(num, sum);
        year = AD + sum;
        month = p.first;
        day = p.second;
    }

    printf("%d %d %d\n", day, month, year);
}

bool End(LL num){ //判断到没到1582年的结尾
    return num <= 77; //十月少了10天,剩下的只剩下77+天了
}

void Solve_ST(LL &num){
    num += 10 + 4;
    int sum = 0, year, month, day;

    for(register int i = 10; i <= 12; i++){
        if(num < RMonth[i]){
            month = i;
            break;
        }
        num -= RMonth[i];
    }
    if(num == 0) ++sum, month = 1, num = 1;
    year = STG + sum;
    day = num + 1;

    printf("%d %d %d\n", day, month, year);
}

bool Leap(LL num){ //判断到没到1600年四百年一轮回
    return num <= 1LL * 4 * Ryear + 13 * Pyear - 1;
}

bool Cut_Year_LE(LL &num, int &sum){
    if(num < Pyear) return false;
    if(num >= Pyear) num -= Pyear, ++sum;
    if(num < Ryear) return true;
    if(num >= Ryear) num -= Ryear, ++sum;

    LL cnt = num / (Ryear + 3 * Pyear);
    num -= 1LL * cnt * (Ryear + 3 * Pyear);
    sum += 4 * cnt;

    if(num < Pyear) return false;

    int tot = 0;
    while(num > Pyear){
        num -= Pyear;
        ++tot;
    }
    if(num == Ryear) num -= Ryear, ++sum;
    sum += tot;

    if((tot == 3 && num != 0) || sum == 1)
        return true;
    else return false;
}

void Solve_LE(LL &num){ //没到1600年四百年一轮回
    int sum = 0, year, month, day;
    if(Cut_Year_LE(num, sum)){
        Pair p = Cut_Month_R(num, sum);
        year = STG + 1 + sum;
        month = p.first;
        day = p.second;
    }
    else{
        Pair p = Cut_Month_P(num, sum);
        year = STG + 1 + sum;
        month = p.first;
        day = p.second;
    }

    printf("%d %d %d\n", day, month, year);
}

bool Cut_Year_GL(LL &num, int &sum){ //现在,是400年大轮回的时刻
    const LL ReFour = 97 * Ryear + 303 * Pyear;
    LL cnt = num / ReFour;
    num -= 1LL * cnt * ReFour;
    sum += 400 * cnt;

    if(num < Ryear) return true; //恰好躺在下个周期的第一年上了,是闰年

    LL now = REST + sum; //当前的年份
    while(1){
        if(now % 100){
            if(now % 4){
                if(num <= Pyear) break;
                else num -= Pyear, ++sum, ++now;
            }
            else{
                if(num <= Ryear) break;
                else num -= Ryear, ++sum, ++now;
            }
        }
        else{
            if(now % 400){
                if(num <= Pyear) break;
                else num -= Pyear, ++sum, ++now;
            }
            else{
                if(num <= Ryear) break;
                else num -= Ryear, ++sum, ++now;
            }
        }
    }
    if(now == 0) ++now;

    if(now % 100){
        if(now % 4) return false;
        else return true;
    }
    else{
        if(now % 400) return false;
        else return true;
    }
}

void Solve_GL(LL &num){
    int sum = 0, year, month, day;

    if(Cut_Year_GL(num, sum)){
        Pair p = Cut_Month_R(num, sum);
        year = REST + sum;
        month = p.first;
        day = p.second;
    }
    else{
        Pair p = Cut_Month_P(num, sum);
        year = REST + sum;
        month = p.first;
        day = p.second;
    }

    printf("%d %d %d\n", day, month, year);
}

int main(){
    q = read();
    while(q--){
        r = read();

        if(BC(r)) Solve_BC(r);
        else{
            r -= Ryear * 1178 + Pyear * 3535 + 1; //减去公元前的部分

            if(Gregorian(r)) Solve_RL(r);
            else{
                r -= 395 * Ryear + 1186 * Pyear + 276 + 1;
                if(End(r)) Solve_ST(r);
                else{
                    r -= 77 + 1;
                    if(Leap(r)) Solve_LE(r);
                    else{
                        r -= 4 * Ryear + 13 * Pyear;
                        Solve_GL(r);
                    }
                }
            }
        }
    }

    return 0;
}

P7426 [THUPC2017] 体育成绩统计

点击折叠代码, 防止大家看了恶心
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>

#define LL long long

using namespace std;

const int MAXN = 1e4 + 10, MAXM = 1.5e5 + 10;
const long double EPS = 1e-12;
const int Month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n, m, cnt;
string x;
unordered_map< LL, int > pos; //映射这个学号的阳光长跑成绩会到哪个vector里
unordered_map< LL, int > sex; //映射这个学号对应学生的性别

struct Student{
    int sex; //性别
    int PE_score; //体育课专项成绩
    int run_score; //期末长跑对应的成绩
    int class_time; //参加班级训练营次数
    int sun_run_time; //阳光长跑次数
    int sun_run_score; //阳光长跑成绩
    int physical_score; //体质检测通过情况成绩
    int freshman_score; //大一专项计划成绩
    int final_score; //最终的成绩

    LL num; //学号

    string grade; //最后的等级
}s[MAXN];

bool cmp1(const Student &a, const Student &b){
    return a.num < b.num;
}

struct Sunshine_Run{ //阳光长跑记录
    LL date; //完成日期
    LL num; //来源学号
    LL st; //开始时间
    LL ed; //结束时间
    LL len; //运动距离 转化到米
    LL broke; //暂停时间 全部转化成秒
    LL sum; //总步数
};

vector<Sunshine_Run> r[MAXM];
int tot[MAXN]; //对应的vector所对应的合法阳光长跑次数

bool cmp2(const Sunshine_Run &a, const Sunshine_Run &b){
    if(a.date != b.date) return a.date < b.date;
    if(a.st != b.st) return a.st < b.st;
    if(a.ed != b.ed) return a.ed < b.ed;
    return a.broke < b.broke;
}

int Get_Sex(string s){
    if(s[0] == 'M') return 1; //男同学
    else return 2; //女同学
}

int Get_Run_Score(string s, int sex){
    int pos_min = s.find('\''), pos_sec = s.find('\"');
    int min = 0, sec = 0, times;

    for(register int i = 0; i < pos_min; i++)
        min = (min << 1) + (min << 3) + (s[i] ^ 48);
    for(register int i = pos_min + 1; i < pos_sec; i++)
        sec = (sec << 1) + (sec << 3) + (s[i] ^ 48);
    
    times = min * 60 + sec;

    if(sex == 1){ //男生
        if(times <= 750) return 20;
        else if(times <= 780) return 18;
        else if(times <= 810) return 16;
        else if(times <= 840) return 14;
        else if(times <= 870) return 12;
        else if(times <= 910) return 10;
        else if(times <= 950) return 8;
        else if(times <= 990) return 6;
        else if(times <= 1030) return 4;
        else if(times <= 1080) return 2;
        else return 0;
    }
    else{ //女生
        if(times <= 400) return 20;
        else if(times <= 417) return 18;
        else if(times <= 434) return 16;
        else if(times <= 451) return 14;
        else if(times <= 470) return 12;
        else if(times <= 485) return 10;
        else if(times <= 500) return 8;
        else if(times <= 515) return 6;
        else if(times <= 530) return 4;
        else if(times <= 540) return 2;
        else return 0;
    }
}

int Get_Physical_Score(string s){
    if(s[0] == 'P') return 10;
    else return 0;
}

LL Get_Time(string s){
    int pos_hou = 2, pos_min = 5, pos_sec = 8;
    LL times, hou = 0, min = 0, sec = 0;

    for(register int i = 0; i < pos_hou; i++)
        hou = (hou << 1) + (hou << 3) + (s[i] ^ 48);
    for(register int i = pos_hou + 1; i < pos_min; i++)
        min = (min << 1) + (min << 3) + (s[i] ^ 48);
    for(register int i = pos_min + 1; i < pos_sec; i++)
        sec = (sec << 1) + (sec << 3) + (s[i] ^ 48);
    
    times = hou * 3600 + min * 60 + sec;

    return times;
}

LL Get_Break(string s){
    int pos_min = s.find('\''), pos_sec = s.find('\"');
    LL min = 0, sec = 0, times;

    for(register int i = 0; i < pos_min; i++)
        min = (min << 1) + (min << 3) + (s[i] ^ 48);
    for(register int i = pos_min + 1; i < pos_sec; i++)
        sec = (sec << 1) + (sec << 3) + (s[i] ^ 48);
    
    times = min * 60 + sec;

    return times;
}

bool Check_Len(LL len, int type){ //检查长跑距离是否合法
    if(type == 1) return len >= 3000 ;//男生
    else return len >= 1500; //女生
}

bool Check_Break(LL times){
    return times <= 270;
}

bool Check_Stride(LL len, LL sum){
    long double d = 1.0 * len / sum;
    return d - 1.5 <= EPS;
}

bool Check_Speed(LL st, LL ed, LL len){
    LL times = ed - st;
    long double speed = 1.0 * len / times;
    return (speed - 2.0 >= EPS && speed - 5.0 <= EPS);
}

bool Check_Time(vector<Sunshine_Run> v, int last, int now){
    LL now_st = v[now].st, last_ed = v[last].ed;
    LL date_now = v[now].date, date_last = v[last].date;
    int month_now = (date_now % 10000) / 100, day_now = date_now % 100;
    int month_last = (date_last % 10000) / 100, day_last = date_last % 100;

    if(month_now - month_last > 1) return true; //都超过一个月了,肯定合法了
    if(month_now - month_last == 1) day_now += Month[month_last]; //差一个月,强行搞到一个月去

    if(day_now - day_last > 1) return true; //超过同一天了,肯定合法
    if(day_now - day_last == 1){ //隔一天
        LL time_now = 24 * 3600 + now_st;
        return time_now - last_ed >= 21600;
    }
    else return now_st - last_ed >= 21600;
}

int Get_Num(vector<Sunshine_Run> v){ //合法的阳光长跑次数
    int cnt = 0; //计数
    LL last = -1; //上一次合法的阳光长跑的编号

    for(register int i = 0; i < v.size(); i++){
        int gen = sex[v[i].num]; //对应的性别
        LL st = v[i].st, ed = v[i].ed, broke = v[i].broke, len = v[i].len, sum = v[i].sum;
        if(!Check_Len(len, gen) || !Check_Break(broke)) continue;
        if(!Check_Stride(len, sum) || !Check_Speed(st, ed, len)) continue;

        if(last == -1){
            ++cnt, last = i;
            continue;
        }

        if(Check_Time(v, last, i)) ++cnt, last = i;
    }

    return cnt;
}

int Get_Sun_Run_Score(int num){
    if(num >= 21) return 10;
    else if(num >= 19) return 9;
    else if(num >= 17) return 8;
    else if(num >= 14) return 7;
    else if(num >= 11) return 6;
    else if(num >= 7) return 4;
    else if(num >= 3) return 2;
    else return 0;
}

int Get_Freshman_Score(int num){
    if(num >= 18) return 5;
    else if(num >= 15) return 4;
    else if(num >= 12) return 3;
    else if(num >= 9) return 2;
    else if(num >= 6) return 1;
    else return 0;
}

void Get_Final_Score(Student &s){
    s.final_score = s.PE_score + s.run_score + s.sun_run_score + s.physical_score + s.freshman_score;

    if(s.final_score >= 95) s.grade = "A";
    else if(s.final_score >= 90) s.grade = "A-";
    else if(s.final_score >= 85) s.grade = "B+";
    else if(s.final_score >= 80) s.grade = "B";
    else if(s.final_score >= 77) s.grade = "B-";
    else if(s.final_score >= 73) s.grade = "C+";
    else if(s.final_score >= 70) s.grade = "C";
    else if(s.final_score >= 67) s.grade = "C-";
    else if(s.final_score >= 63) s.grade = "D+";
    else if(s.final_score >= 60) s.grade = "D";
    else s.grade = "F";
}

int main(){
    ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    cin >> n;
    for(register int i = 1; i <= n; i++){
        cin >> s[i].num;
        cin >> x, s[i].sex = Get_Sex(x);
        cin >> s[i].PE_score;
        cin >> x, s[i].run_score = Get_Run_Score(x, s[i].sex);
        cin >> x, s[i].physical_score = Get_Physical_Score(x);
        cin >> s[i].freshman_score;
        cin >> s[i].class_time;
        sex[s[i].num] = s[i].sex;
    }
    
    cin >> m;
    for(register int i = 1; i <= m; i++){
        LL date, num, sum;
        long double len;
        string st, ed, broke;
        cin >> date >> num >> st >> ed >> len >> broke >> sum;

        if(!pos[num]) pos[num] = ++cnt;

        int to;
        LL time_st, time_ed, len_m, time_broke;
        time_st = Get_Time(st), time_ed = Get_Time(ed);
        time_broke = Get_Break(broke), len_m = len * 1000;
        to = pos[num]; //应该存到哪个vector里
        r[to].push_back((Sunshine_Run){date, num, time_st, time_ed, len_m, time_broke, sum});
    }

    for(register int i = 1; i <= cnt; i++){
        sort(r[i].begin(), r[i].end(), cmp2);
        tot[i] = Get_Num(r[i]);
    }

    for(register int i = 1; i <= n; i++){
        s[i].sun_run_time = tot[pos[s[i].num]];
        s[i].sun_run_score = Get_Sun_Run_Score(s[i].sun_run_time);
        s[i].freshman_score += Get_Freshman_Score(s[i].class_time + s[i].sun_run_time);
        Get_Final_Score(s[i]);
    }
    
    sort(s + 1, s + 1 + n, cmp1);

    for(register int i = 1; i <= n; i++)
        cout << s[i].num << " " << s[i].final_score << " " << s[i].grade << "\n";
    
    return 0;
}
posted @ 2022-10-04 11:32  TSTYFST  阅读(96)  评论(6编辑  收藏  举报