mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-07-07 18:06:58 +08:00
upload some new code
This commit is contained in:
60
Luogu/P1219 [USACO1.5] 八皇后 Checker Challenge.cpp
Normal file
60
Luogu/P1219 [USACO1.5] 八皇后 Checker Challenge.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
#define debug$ if(dev)
|
||||
using namespace std;
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
const bool dev = false;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
int a[N], b[N], c[N], d[N];
|
||||
int total;
|
||||
int n;
|
||||
|
||||
void print()
|
||||
{
|
||||
if (total <= 2)
|
||||
{
|
||||
for (int k = 1; k <= n; k++)
|
||||
cout << a[k] << " ";
|
||||
cout << endl;
|
||||
}
|
||||
total++;
|
||||
}
|
||||
void queen(int i)
|
||||
{
|
||||
if (i > n)
|
||||
{
|
||||
print();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 1; j <= n; j++)
|
||||
{
|
||||
if ((!b[j]) && (!c[i + j]) && (!d[i - j + n]))
|
||||
{
|
||||
a[i] = j;
|
||||
b[j] = 1;
|
||||
c[i + j] = 1;
|
||||
d[i - j + n] = 1;
|
||||
queen(i + 1);
|
||||
b[j] = 0;
|
||||
c[i + j] = 0;
|
||||
d[i - j + n] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
signed main()
|
||||
{
|
||||
cin >> n;
|
||||
queen(1);
|
||||
cout << total;
|
||||
return 0;
|
||||
}
|
23
Luogu/【模板】排序.cpp
Normal file
23
Luogu/【模板】排序.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int a[N];
|
||||
|
||||
signed main()
|
||||
{
|
||||
int n;
|
||||
cin >> n ;
|
||||
for(int i = 1; i <= n; i ++ ) cin >> a[i] ;
|
||||
sort(a + 1, a + 1 + n);
|
||||
for(int i = 1; i <= n; i ++ ) cout << a[i] << " " ;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user