[go: nahoru, domu]

Skip to content

Commit

Permalink
update jisuanke
Browse files Browse the repository at this point in the history
  • Loading branch information
lzyrapx committed Sep 19, 2020
1 parent 344f0c0 commit 6b0eea7
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 108 deletions.
210 changes: 102 additions & 108 deletions jisuanke/2020计蒜之道第一场/A.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,128 +6,122 @@
using namespace std;

// 五子棋,黑色棋子先手
vector<string>ve;
vector<string> ve;
char next_step;

int tran(int x, int y) {
int cnt = 0, nx = x, ny = y - 1;
while(ny >= 0 && ve[nx][ny] == next_step)
{
cnt++;
ny--;
}
ny = y + 1;
while(ny < 25 && ve[nx][ny] == next_step)
{
cnt++;
ny++;
}
if(cnt >= 4) return 1;
else return 0;
while (ny >= 0 && ve[nx][ny] == next_step) {
cnt++;
ny--;
}
ny = y + 1;
while (ny < 25 && ve[nx][ny] == next_step) {
cnt++;
ny++;
}
if (cnt >= 4)
return 1;
else
return 0;
}

bool vertical(int x, int y)
{
int cnt = 0, nx = x - 1, ny = y;
while(nx >= 0 && ve[nx][ny] == next_step)
{
cnt++;
nx--;
}
nx = x + 1;
while(nx < 25 && ve[nx][ny] == next_step)
{
cnt++;
nx++;
}
if(cnt >= 4) return 1;
else return 0;
bool vertical(int x, int y) {
int cnt = 0, nx = x - 1, ny = y;
while (nx >= 0 && ve[nx][ny] == next_step) {
cnt++;
nx--;
}
nx = x + 1;
while (nx < 25 && ve[nx][ny] == next_step) {
cnt++;
nx++;
}
if (cnt >= 4)
return 1;
else
return 0;
}

bool MainDiagonal(int x, int y)
{
int cnt = 0, nx = x - 1, ny = y - 1;
while(nx >= 0 && ny >= 0 && ve[nx][ny] == next_step)
{
cnt++;
nx--;
ny--;
}
nx = x + 1, ny = y + 1;
while(nx < 25 && ny < 25 && ve[nx][ny] == next_step)
{
cnt++;
nx++;
ny++;
}
if(cnt >= 4) return 1;
else return 0;
bool MainDiagonal(int x, int y) {
int cnt = 0, nx = x - 1, ny = y - 1;
while (nx >= 0 && ny >= 0 && ve[nx][ny] == next_step) {
cnt++;
nx--;
ny--;
}
nx = x + 1, ny = y + 1;
while (nx < 25 && ny < 25 && ve[nx][ny] == next_step) {
cnt++;
nx++;
ny++;
}
if (cnt >= 4)
return 1;
else
return 0;
}

bool SubDiagonal(int x, int y)
{
int cnt = 0, nx = x - 1, ny = y + 1;
while(nx >= 0 && ny < 25 && ve[nx][ny] == next_step)
{
cnt++;
nx--;
ny++;
}
nx = x + 1, ny = y - 1;
while(nx < 25 && ny >= 0 && ve[nx][ny] == next_step)
{
cnt++;
nx++;
ny--;
}
if(cnt >= 4) return 1;
else return 0;
bool SubDiagonal(int x, int y) {
int cnt = 0, nx = x - 1, ny = y + 1;
while (nx >= 0 && ny < 25 && ve[nx][ny] == next_step) {
cnt++;
nx--;
ny++;
}
nx = x + 1, ny = y - 1;
while (nx < 25 && ny >= 0 && ve[nx][ny] == next_step) {
cnt++;
nx++;
ny--;
}
if (cnt >= 4)
return 1;
else
return 0;
}

int main(int argc, char const *argv[])
{

int n;
string s;
for(int i = 0; i < 25; i++) {
cin >> s;
ve.push_back(s);
}
int white = 0, black = 0;
for(int i = 0; i < 25; i++) {
for(int j = 0; j < 25; j++) {
if(ve[i][j] == 'o') {
white++;
}
if(ve[i][j] == 'x') {
black++;
}
}
int main(int argc, char const *argv[]) {
int n;
string s;
for (int i = 0; i < 25; i++) {
cin >> s;
ve.push_back(s);
}
int white = 0, black = 0;
for (int i = 0; i < 25; i++) {
for (int j = 0; j < 25; j++) {
if (ve[i][j] == 'o') {
white++;
}
if (ve[i][j] == 'x') {
black++;
}
}
if(white == black) {
next_step = 'x';
}
else {
next_step = 'o';
}
vector< pair<int,int> >ans;
for(int i = 0; i < 25; i++) {
for(int j = 0; j < 25; j++) {
if(ve[i][j] == '.') {
if(tran(i, j) || vertical(i, j) || MainDiagonal(i, j) || SubDiagonal(i, j)) {
ans.push_back(make_pair(i, j));
}
}
}
}
if(ans.size() == 0) {
cout << "tie" << endl;
return 0;
}
else {
for(int i = 0; i < (int)ans.size(); i++) {
cout << ans[i].first << " " << ans[i].second << endl;
}
if (white == black) {
next_step = 'x';
} else {
next_step = 'o';
}
vector<pair<int, int> > ans;
for (int i = 0; i < 25; i++) {
for (int j = 0; j < 25; j++) {
if (ve[i][j] == '.') {
if (tran(i, j) || vertical(i, j) || MainDiagonal(i, j) ||
SubDiagonal(i, j)) {
ans.push_back(make_pair(i, j));
}
}
}
}
if (ans.size() == 0) {
cout << "tie" << endl;
return 0;
} else {
for (int i = 0; i < (int)ans.size(); i++) {
cout << ans[i].first << " " << ans[i].second << endl;
}
}
return 0;
}
47 changes: 47 additions & 0 deletions jisuanke/2020计蒜之道第一场/B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>

using namespace std;

const int maxn = 3 * 1e5 + 123;
int m, n;
int black[maxn];
int white[maxn];
int t[maxn], l[maxn], r[maxn], c[maxn];
int seg[maxn];
int main(int argc, char const *argv[]) {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> black[i];
}
for (int i = 1; i <= n; i++) {
cin >> white[i];
}
for (int i = 1; i <= m; i++) {
cin >> t[i] >> l[i] >> r[i] >> c[i];
for (int j = l[i]; j <= r[i]; j++) seg[j] = 1; //在区间
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
if (seg[i] == 0) {
ans += max(black[i], white[i]);
}
}
for (int i = 1; i <= m; i++) {
long long maxx = 0, black_seg = 0, white_seg = 0;
for (int j = l[i]; j <= r[i]; j++) {
black_seg += black[j];
white_seg += white[j];
maxx += max(black[j], white[j]);
}
if (t[i] == 1) {
ans += max(maxx, c[i] + black_seg);
} else {
ans += max(maxx, c[i] + white_seg);
}
}
cout << ans << endl;
return 0;
}

0 comments on commit 6b0eea7

Please sign in to comment.