2
6 9 3 5 1
5 10 7 8 6

LOSE
WIN

## AC代码:

#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5+5;
const double eps = 1e-5;
const double e = 2.718281828459;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
ll l1, r1, l2, r2, mod;
cin >> l1 >> r1 >> l2 >> r2 >> mod;
if (r2 - l2 + 1 < mod) {
cout << "WIN" << endl;
}
else {
cout << "LOSE" << endl;
}
}
return 0;
}

## AC代码:

#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 1e6+5;
const double eps = 1e-5;
const double e = 2.718281828459;

int t;
int l1, r1, l2, r2, mod;
set<int> rem;
bool len_vis[10];
bool rem_flag[maxn][2];
bool ans_flag;
set<int> len_rem[10];

int Cal_num_len(int x) {
int cnt = 0;
while (x) {
x /= 10;
cnt++;
}
cnt = cnt == 0 ? 1 : cnt;
return cnt;
}

int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while (t--) {
mem(len_vis, 0);
mem(rem_flag, 0);
cin >> l1 >> r1 >> l2 >> r2 >> mod;
if (r2 - l2 + 1 >= mod) {
cout << "LOSE" << endl;
continue;
}
for (int i = l1; i <= r1; ++i) {
rem.insert(i % mod);
rem_flag[i % mod][0] = 1;
}
for (int i = l2; i <= r2; ++i) {
int num_len_temp = Cal_num_len(i);
len_vis[num_len_temp] = 1;
len_rem[num_len_temp].insert(i % mod);
}
for (set<int>::iterator rem_it = rem.begin(); rem_it != rem.end(); ++rem_it) {
for (int j = 0; j < 10; ++j) {
if (len_vis[j]) {
for (set<int>::iterator len_rem_it = len_rem[j].begin(); len_rem_it != len_rem[j].end(); ++len_rem_it) {
if ((*rem_it + *len_rem_it) % mod == 0) {
rem_flag[*rem_it][1] = 1;
}
}
}
}
}
ans_flag = 1;
for (int i = 0; i <= mod; ++i) {
if (rem_flag[i][0]) {
if (!rem_flag[i][1]) {
ans_flag = 0;
break;
}
}
}
if (ans_flag) {
cout << "LOSE";
}
else {
cout << "WIN";
}
cout << endl;
rem.clear();
for (int i = 0; i < 10; ++i) {
len_rem[i].clear();
}
}
return 0;
}

Last modification：March 29th, 2019 at 04:51 pm