1. 程式人生 > >【noip題目程式碼】魔法陣;模擬,iterator,

【noip題目程式碼】魔法陣;模擬,iterator,


#include<vector>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXSIZE 15001

//1000000000

struct node{
    int A = 0;
    int B = 0;
    int C = 0;
    int D = 0;
    int L = 0;
    int book = 0;
};

std::vector<node> v;
std::vector<node> vAns;
std
::vector<int> inArr; node nodeArr[MAXSIZE]; // TODO int arr[MAXSIZE] = { 0 }; int ans[5][MAXSIZE] = { 0 }; int main() { int n = 0, m = 0; int x = 0; int A = 0, B = 0, C = 0, D = 0; cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> x; arr[x] += 1
; inArr.push_back(x); nodeArr[x].book = 1; } for (int L = 1; L < n; L++) { for (int i = 0; i < MAXSIZE; i++) { if (arr[i] >= 1)// 假設當前的點是A { A = i; if (arr[A + 2 * L] >= 1)// B存在 { B = A + 2
* L; node temp; temp.A = A; temp.B = B; temp.L = L; v.push_back(temp); } } } } for (int i = 0; i < v.size(); i++) { for (int j = 1; j < n; j++)// TODO { if (v[i].B + 6 * v[i].L + j < n && arr[v[i].B + 6 * v[i].L + j] >= 1)// 找到ABCD成立的情況 { v[i].C = v[i].B + 6 * v[i].L + j; if (v[i].B + 6 * v[i].L + j < n && arr[v[i].L + v[i].C] >= 1) { v[i].D = v[i].L + v[i].C; vAns.push_back(v[i]); nodeArr[v[i].A].A += 1; nodeArr[v[i].B].B += 1; nodeArr[v[i].C].C += 1; nodeArr[v[i].D].D += 1; if (arr[v[i].A] > 1 || arr[v[i].B] > 1 || arr[v[i].C] > 1 || arr[v[i].D] > 1) { int temp1 = max(arr[v[i].A], arr[v[i].B]); int temp2 = max(arr[v[i].C], arr[v[i].D]); temp1 = max(temp1, temp2); nodeArr[v[i].A].A *= temp1; nodeArr[v[i].B].B *= temp1; nodeArr[v[i].C].C *= temp1; nodeArr[v[i].D].D *= temp1; } /*ans[1][v[i].A] += 1; ans[2][v[i].B] += 1; ans[3][v[i].C] += 1; ans[4][v[i].D] += 1;*/ } } } } //for (int i = 0; i < MAXSIZE; i++) //{ // if (arr[i] > 1) // { // vAns // } //} for (int i = 0; i < inArr.size(); i++) { if (nodeArr[inArr[i]].book >= 1) { //if (arr[inArr[i]]>=) cout << nodeArr[inArr[i]].A << " " << nodeArr[inArr[i]].B << " " << nodeArr[inArr[i]].C << " " << nodeArr[inArr[i]].D << endl; } } return 0; }