1003 : M i n e S w e e p e r 1003:Mine Sweeper 1003:MineSweeper
随机思路:
可用srand()随机化坐标暴力跑点过,但是运气特别不好就可能会
T
L
E
TLE
TLE,但存在一个概率问题,口胡一下可行性:
对于一个
25
∗
25
25*25
25∗25的图,我们按照一定要求跑数字和为
S
S
S,跑出
1
,
2
,
.
.
.
.
1,2,....
1,2,....小于
12
12
12左右的数的概率比较低,因为
25
∗
25
25*25
25∗25组成这些数字和的图比较少,而数字越大,组成这个图的方案就越多,跑出来的概率就会十分的高,速度就会很快,然后可以用暴力跑验证一下,发现在跑
12
12
12时,有些卡顿,跑
1
,
2
,
4
,
7
1,2,4,7
1,2,4,7时跑不出来,其余都能以很快的速度跑出来,然后特判这些很慢的点,其余数据用随机跑点即可,会
A
C
AC
AC的概率大,也有
T
L
E
TLE
TLE的概率。
官方题解:
参考代码:
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
typedef long long ll;
//#define ll long long
const ll N = 2e3 + 20;
const int maxn = 5e5 + 20;
const ll mod = 1000000007;
ll inv[maxn], vis[maxn], dis[maxn], head[maxn], dep[maxn], out[maxn];
ll fac[maxn], a[maxn], b[maxn], c[maxn], pre[maxn], cnt, sizx[maxn];
vector<ll> vec;
char s[28][28];
//typedef pair<ll, ll> p;
//priority_queue<p, vector<p>, greater<p> > m;
//ll sum[maxn];
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
void swap(int &x, int &y) { x ^= y, y ^= x, x ^= y; }
map<ll, ll> mp;
ll ksm(ll a, ll b)
{
a %= mod;
ll ans = 1ll;
while (b)
{
if (b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1ll;
}
return ans;
}
ll lowbit(ll x)
{
return x & (-x);
}
int sum, n;
int check(int x, int y) { return x > y; }
void dfs(int x, int step)
{
if (step == n + 1)
{
sum = (sum + 1) % mod;
return;
}
for (int i = 1; i <= n; i++)
{
if (!vis[i] && (check(x, i) == b[step]))
{
vis[i] = 1;
dfs(i, step + 1);
vis[i] = 0;
}
}
}
int dir[8][2] = {1, 0, 0, 1, 0, -1, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
srand(time(NULL));
int t, m, k, n;
cin >> t;
for (int m = 1; m <= t; m++)
{
cin >> n;
if (n == 1)
{
cout << 1 << ' ' << 2 << endl;
cout << "X." << endl;
continue;
}
if (n == 2)
{
cout << 1 << ' ' << 3 << endl;
cout << "X.X" << endl;
continue;
}
if (n == 4)
{
cout << 1 << ' ' << 5 << endl;
cout << "X.X.X" << endl;
continue;
}
if (n == 7)
{
cout << 2 << ' ' << 4 << endl;
cout << "X..X" << endl;
cout << "X..." << endl;
continue;
}
if (n == 12)
{
cout << 4 << ' ' << 3 << endl;
cout << "X.." << endl;
cout << ".X." << endl;
cout << "X.." << endl;
cout << "..." << endl;
continue;
}
for (int i = 1; i <= 25; i++)
{
for (int j = 1; j <= 25; j++)
{
s[i][j] = '.';
}
}
int ans = 0;
while (ans != n)
{
int x = rand() % 25 + 1;
int y = rand() % 25 + 1;
if (ans < n)
{
if (s[x][y] != 'X')
{
s[x][y] = 'X';
for (int i = 0; i < 8; i++)
{
int xx = x + dir[i][0];
int yy = y + dir[i][1];
if (xx <= 0 || xx > 25 || yy <= 0 || yy > 25)
continue;
if (s[xx][yy] == '.')
ans++;
if (s[xx][yy] == 'X')
ans--;
}
}
}
else if (ans > n)
{
if (s[x][y] == 'X')
{
s[x][y] = '.';
for (int i = 0; i < 8; i++)
{
int xx = x + dir[i][0];
int yy = y + dir[i][1];
if (xx <= 0 || xx > 25 || yy <= 0 || yy > 25)
continue;
if (s[xx][yy] == '.')
ans--;
if (s[xx][yy] == 'X')
ans++;
}
}
}
}
cout << 25 << ' ' << 25 << endl;
for (int i = 1; i <= 25; i++)
{
for (int j = 1; j <= 25; j++)
{
cout << s[i][j];
}
cout << endl;
}
}
}
1004 : P e r m u t a t i o n C o u n t i n g 1004:Permutation Counting 1004:PermutationCounting
没看懂题解,dp题做的太少,这个目前看不懂,回头再补。
1011 : T a s k S c h e d u l e r 1011:Task Scheduler 1011:TaskScheduler
结论题:可以打表找一下规律,或者手写几组找 k > 0 k>0 k>0的规律, k = = 0 k==0 k==0,显然要字典序最小,按顺序输出即可,反则按机器数量降序输出 i d id id即可
官方题解:
参考代码:
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
typedef long long ll;
//#define ll long long
const ll N = 2e3 + 20;
const int maxn = 5e5 + 20;
const ll mod = 1000000007;
ll inv[maxn], vis[maxn], dis[maxn], head[maxn], dep[maxn], out[maxn];
ll fac[maxn], a[maxn], b[maxn], c[maxn], pre[maxn], cnt, sizx[maxn];
vector<ll> vec;
char s[28][28];
//typedef pair<ll, ll> p;
//priority_queue<p, vector<p>, greater<p> > m;
//ll sum[maxn];
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
void swap(int &x, int &y) { x ^= y, y ^= x, x ^= y; }
map<ll, ll> mp;
ll ksm(ll a, ll b)
{
a %= mod;
ll ans = 1ll;
while (b)
{
if (b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1ll;
}
return ans;
}
ll lowbit(ll x)
{
return x & (-x);
}
int sum, n;
int check(int x, int y) { return x > y; }
void dfs(int x, int step)
{
if (step == n + 1)
{
sum = (sum + 1) % mod;
return;
}
for (int i = 1; i <= n; i++)
{
if (!vis[i] && (check(x, i) == b[step]))
{
vis[i] = 1;
dfs(i, step + 1);
vis[i] = 0;
}
}
}
int dir[8][2] = {1, 0, 0, 1, 0, -1, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1};
struct node
{
int k, w;
} pl[maxn];
bool cmp(node a, node b)
{
if (a.w == b.w)
return a.k < b.k;
return a.w > b.w;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
srand(time(NULL));
int t, m, k, n;
cin >> t;
while (t--)
{
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
cin >> pl[i].w, pl[i].k = i;
if (!k)
{
for (int i = 1; i <= n; i++)
{
if (i != n)
cout << i << ' ';
else
cout << i << endl;
}
}
else
{
sort(pl + 1, pl + 1 + n, cmp);
for (int i = 1; i <= n; i++)
{
if (i != n)
cout << pl[i].k << ' ';
else
cout << pl[i].k << endl;
}
}
}
}