L1-072 刮刮彩票

题目 L1-072 刮刮彩票

image-a0570a26

思路分析

懒得想 打表

其实可以用类似n皇后的方法

正对角线x+y 反对角线 n-x+y

代码实现

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

using ll = long long;

using ull = unsigned long long;

using PII = pair<int,int>;

using Pll = pair<ll,ll>;

int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1};

const int inf = 0x3f3f3f3f;

const int N=5;

int g[N][N];

multiset<int> used= {1,2,3,4,5,6,7,8,9};

int main() {

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

	for(int i=1; i<=3; i++) {

		for(int j=1; j<=3; j++) {

			cin>>g[i][j];

			if(g[i][j]!=0)	used.erase(g[i][j]);

		}

	}

	int shengyu;

	for(auto v:used)	shengyu=v;

	for(int i=1; i<=3; i++) {

		for(int j=1; j<=3; j++) {

			if(g[i][j]==0) g[i][j]=shengyu;

		}

	}

	for(int i=0; i<3; i++) {

		int h,l;

		cin>>h>>l;

		cout<<g[h][l]<<endl;

	}

	int money[30]= {0,0,0,0,0,0,10000,36,720,360,80,252,108,72,54,180,72,180,119,36,306,1080,144,1800,3600};

	int x;

	cin>>x;

	if(x==1) {

		cout<<money[g[1][1]+g[1][2]+g[1][3]];

	} else if(x==2) {

		cout<<money[g[2][1]+g[2][2]+g[2][3]];

	} else if(x==3) {

		cout<<money[g[3][1]+g[3][2]+g[3][3]];

	} else if(x==4) {

		cout<<money[g[1][1]+g[2][1]+g[3][1]];

	} else if(x==5) {

		cout<<money[g[1][2]+g[2][2]+g[3][2]];

	} else if(x==6) {

		cout<<money[g[1][3]+g[2][3]+g[3][3]];

	} else if(x==7) {

		cout<<money[g[1][1]+g[2][2]+g[3][3]];

	} else if(x==8) {

		cout<<money[g[1][3]+g[2][2]+g[3][1]];

	}

	return 0;

}

同类题型

视频讲解


⬅️ L1-071 前世档案 🏠 00-天梯赛 ➡️ L1-073 人与神