This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,52 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct Node {
int number; // 数字
int cnt; // 几根木棍
} a[6] = {{1, 2}, {2, 5}, {4, 4}, {6, 6}, {7, 3}, {8, 7}};
/**
* u 第几个位置
* r 剩余木棍数
* s 当前数字
*/
LL res = LONG_LONG_MAX;
void dfs(int u, int r, LL s) {
if (r == 0) {
res = min(res, s);
return;
}
for (int i = 0; i < 6; i++)
if (a[i].cnt <= r) {
if (u > 1 && a[i].number == 6)
dfs(u + 1, r - a[i].cnt, s * 10);
else
dfs(u + 1, r - a[i].cnt, s * 10 + a[i].number);
}
}
int main() {
// 我们要找到一个数字,这个数字要使用掉指定数量的木棍,比如 n=1
// n=1 拼不出来,输出-1
// n=2 1
// n=3 7
// n=4 4
// n=5 2
// n=6 6
// n=7 8
// n=8 10
// n=9 18
// n=10 22
// n=11 20
// n=12 28
for (int i = 1; i <= 40; i++) {
res = LONG_LONG_MAX;
if (i > 1)
dfs(1, i, 0);
else
res = -1;
cout << "n=" << i << " " << res << endl;
}
return 0;
}

View File

@@ -0,0 +1,53 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int a[N][N];//装地图,1:代表有障碍物,0:代表是空地,2:代表是空地但我走过
int main() {
//配置从文本文件读入数据
freopen("explore.in","r", stdin);
freopen("explore.out","w", stdout);
int T;
cin >> T;
while(T--){
//多组测试数据清空数据是最重要的
memset(a, 0, sizeof(a));//0:代表是空的,没有输入过
//n, m 表示地图的行数和列数,k 表示机器人执行操作的次数
int n, m, k;
cin >> n >> m >> k;
//(x,y):机器人的初始坐标,d是初始的朝向
int x, y, d;
cin >> x >> y >> d;
a[x][y] = 2;
for (int i = 1; i <= n;i++)
for (int j = 1; j <= m;j++){
char q;
cin >> q;
if (q == 'x') a[i][j] = 1;//障碍物是1,否则是0,0就不填写了
}
//至此,输入结束
while(k--){
int nx, ny;
if (d == 0) nx = x, ny = y + 1;
if (d == 1) nx = x + 1, ny = y;
if (d == 2) nx = x, ny = y - 1;
if (d == 3) nx = x - 1, ny = y;
if(a[nx][ny]==1 || nx>n || ny>m|| nx<1 || ny<1) {
d = (d + 1) % 4;
//cout << "Turn d=" << d << endl;
}
else {
x = nx, y = ny, a[x][y] = 2;
//cout << "x=" << x << ",y=" << y << " d=" << d << endl;
}
}
//输出结果
int cnt = 0;
for (int i = 1;i<=n;i++)
for (int j = 1;j<=m;j++)
if (a[i][j] == 2) cnt++;
cout << cnt << endl;
}
return 0;
}

View File

@@ -0,0 +1,11 @@
2
1 5 4
1 1 2
....x
5 5 20
1 1 0
.....
.xxx.
.x.x.
..xx.
x....

View File

@@ -0,0 +1,2 @@
3
13

View File

@@ -0,0 +1,48 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 53;
int b[N];
int main() {
int n;
cin>>n;
for(int i=1;i<=n;i++){
string op;
cin>>op;
//字符 D 代表方片,字符 C 代表草花,字符 H 代表红桃,字符 S 代表黑桃
char x = op[0];
char num = op[1];
int pos = 0;
switch(x){
case 'D':
pos = 0;
break;
case 'C':
pos = 13;
break;
case 'H':
pos = 26;
break;
case 'S':
pos = 39;
break;
}
if (num <= '9' && num >= '0') pos += num - '0';
else if(num=='T')
pos += 10;
else if (num=='J')
pos += 11;
else if(num=='Q')
pos += 12;
else if(num=='K')
pos += 13;
else if(num=='A')
pos += 1;
b[pos]++;
}
int cnt = 0;
for (int i = 1; i <= 52;i++)
if (b[i]) cnt++;
cout << 52 - cnt << endl;
return 0;
}

View File

@@ -0,0 +1,61 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
// 声明一个结构体存储每个数字的木棍数
struct Node {
int num;
int cnt;
} a[6] = {{0, 6}, {1, 2}, {2, 5}, {4, 4}, {7, 3}, {8, 7}};
LL mi = LONG_LONG_MAX;
string s[7] = {"", "", "", "", "", "", ""};
/*
u: 第几个数字
sum: 拼接出的数字
r: 剩余木棍数
*/
void dfs(int u, LL sum, int r) {
// 递归出口
if (r == 0) { // 如果剩余木棍数是0,说明拼接出了一个数字,输出即可
mi = min(mi, sum);
return;
}
// 遍历每个可能的数字,如果剩余木棍数够用,就选择这个数字
for (int i = 0; i < 6; i++) {
if (a[i].cnt <= r) { // 如果剩余木棍数够用,就选择这个数字
// 如果当前数字是6,并且是前导零,就选择6,否则选择0
int cur = (a[i].num == 0 && u == 1) ? 6 : a[i].num;
// 递归调用,拼接出下一个数字
dfs(u + 1, sum * 10 + cur, r - a[i].cnt);
}
}
}
int main() {
for (int n = 7; n <= 38; n++) {
// 最小值
mi = LONG_LONG_MAX;
// 开启第一轮次,目前拼接出的数字为0,并且还剩18根木棍
dfs(1, 0, n);
// 如果没有找到答案,输出-1
if (mi == LONG_LONG_MAX) {
cout << "n=" << n << ",ans=" << -1 << endl;
} else {
int q = n % 7;
string str = "n=" + to_string(n) + ",ans=" + to_string(mi);
if (s[q] == "") {
s[q] = str;
} else {
s[q] = s[q] + "," + str;
}
}
}
for (int i = 0; i < 7; i++) {
cout << " " << s[i] << endl;
}
return 0;
}

View File

@@ -0,0 +1,49 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
// 声明一个结构体存储每个数字的木棍数
struct Node {
int num;
int cnt;
} a[6] = {{0, 6}, {1, 2}, {2, 5}, {4, 4}, {7, 3}, {8, 7}};
LL mi = LONG_LONG_MAX;
/*
u: 第几个数字
sum: 拼接出的数字
r: 剩余木棍数
*/
void dfs(int u, LL sum, int r) {
// 递归出口
if (r == 0) { // 如果剩余木棍数是0,说明拼接出了一个数字,输出即可
mi = min(mi, sum);
return;
}
// 遍历每个可能的数字,如果剩余木棍数够用,就选择这个数字
for (int i = 0; i < 6; i++) {
if (a[i].cnt <= r) { // 如果剩余木棍数够用,就选择这个数字
// 如果当前数字是6,并且是前导零,就选择6,否则选择0
int cur = (a[i].num == 0 && u == 1) ? 6 : a[i].num;
// 递归调用,拼接出下一个数字
dfs(u + 1, sum * 10 + cur, r - a[i].cnt);
}
}
}
int main() {
for (int n = 1; n <= 35; n++) {
// 最小值
mi = LONG_LONG_MAX;
// 开启第一轮次,目前拼接出的数字为0,并且还剩18根木棍
dfs(1, 0, n);
// 如果没有找到答案,输出-1
if (mi == LONG_LONG_MAX)
cout << "n=" << n << ",ans=" << -1 << endl;
else
cout << "n=" << n << ",ans=" << mi << endl;
}
return 0;
}

View File

@@ -0,0 +1,45 @@
#include <bits/stdc++.h>
using namespace std;
const int f[10] = {0, -1, 1, 7, 4, 2, 6, 8, 10};
int T, n, d, i;
int main() {
for (cin >> T; T--;) {
cin >> n;
if (n <= 8)
cout << f[n];
else {
d = n % 7;
if (!d)
for (i = 1; i <= n / 7; i++) cout << 8;
if (d == 1) {
cout << 10;
for (i = 1; i < n / 7; i++) cout << 8;
}
if (d == 2) {
cout << 1;
for (i = 1; i <= n / 7; i++) cout << 8;
}
if (d == 3) {
if (n == 10)
cout << 22;
else {
cout << 200;
for (i = 1; i <= n / 7 - 2; i++) cout << 8;
}
}
if (d == 4) {
cout << 20;
for (i = 1; i < n / 7; i++) cout << 8;
}
if (d == 5) {
cout << 2;
for (i = 1; i <= n / 7; i++) cout << 8;
}
if (d == 6) {
cout << 6;
for (i = 1; i <= n / 7; i++) cout << 8;
}
}
cout << '\n';
}
}

View File

@@ -0,0 +1,39 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct Node {
int number; // 对应的数字
int cnt; // 数字使用的小木棍数量
} a[6] = {{1, 2}, {2, 5}, {4, 4}, {6, 6}, {7, 3}, {8, 7}};
LL res = LONG_LONG_MAX;
/*
u 从左到右第几个数位
r 剩余木棍数量
s 已经拼接出的数字是多大
*/
void dfs(int u, int r, LL s) {
// 递归出口
if (r == 0) {
res = min(res, s);
return;
}
for (int i = 0; i < 6; i++) {
if (r >= a[i].cnt) {
if (a[i].number == 6 && u > 1)
dfs(u + 1, r - a[i].cnt, s * 10);
else
dfs(u + 1, r - a[i].cnt, s * 10 + a[i].number);
}
}
}
int main() {
for (int i = 2; i <= 30; i++) {
res = LONG_LONG_MAX;
dfs(0, i, 0);
cout << "n=" << i << " number=" << res << endl;
}
return 0;
}

View File

@@ -0,0 +1,47 @@
/*
0~9每个数字的,比如数字0有6个小木棍组成
int b[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int a[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
1、看了一眼数据范围,最大1e5,所以,双重循环的O(N^2)肯定是要挂掉的。
2、观察一下上面的a数组,发现
{2:1}
{3:7}
{4:4}
{5:2,3,5}
{6:0,6,9}
{7:8}
有啥规律呢?我们发现,如果现在需要处理掉5个小木棍,我肯定会贪心的选择2这个数字,而不会去使用3或者5,因为不管怎么样,2可以保证更小的结果。
但6的话需要讨论一下:
(1)非前导零时,选择0
(2)前导零时,选择6,9肯定没用,因为6永远比9划算。所以整理上面的数字规律如下:
{2:1}
{3:7}
{4:4}
{5:2}
{6:0,6}
{7:8}
下面我们找第一个测试用例尝试一下,看看能不能找出什么规律,这时,不要找太极端的数字,即不是最大的,也不是最小的
比如2,输出:1
比如3,输出:7
比如6,输出:6
比如18,输出208
通过6根数,我们为什么没有输出0呢?是因为题目说了,不能有前导零,所以在代码中应该有一个关键词 prefix_zero,用来判断是否是前导零。
那18输出208是怎么回事呢?
2-->5
0-->6
8-->7
5+6+7=18根木棍
6!=6*5*4*3*2*1=720
720*1e5=7.2e7 < 1e8,所以做一个 6!次运算是没有问题的,也就是说,这是一道dfs题
*/
// 数字0:6根木棍
// 数字1:2个木棍
// 数字2:5根木棍
// 数字4:4根木棍
// 数字7:2根木棍
// 数字8:7根木棍

View File

@@ -0,0 +1,71 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct Node {
int number;
int cnt;
} a[6] = {{1, 2}, {2, 5}, {4, 4}, {6, 6}, {7, 3}, {8, 7}};
LL res = LONG_LONG_MAX;
int main() {
int m;
cin >> m;
for (int n = 1;n<=m;n++){
cout << n<<"=";
if (n == 1)
cout << "-1" << endl;
else if (n == 2)
cout << "1" << endl;
else if (n == 3)
cout << "7" << endl;
else if (n == 4)
cout << "4" << endl;
else if (n == 5)
cout << "2" << endl;
else if (n == 6)
cout << "6" << endl;
else if (n == 7)
cout << "8" << endl;
else if (n == 17)
cout << "200" << endl;
else if (n % 7 == 1) {
cout << "10";
for (int i = 1; i < n / 7; i++) cout << "8";
cout << endl;
}
else if(n%7==2){
cout << "1";
for (int i = 1; i <= n / 7; i++) cout << "8";
cout << endl;
}
else if(n%7==3){
if (n == 10) cout << "22";
else {
cout << "200";
for (int i = 1; i <= n / 7-2; i++) cout << "8";
}
cout << endl;
}
else if(n%7==4){
cout << "20";
for (int i = 1;i<n/7;i++)cout<<"8";
cout<<endl;
}
else if(n%7==5){
cout << "2";
for (int i = 1; i <= n/7; i++)cout<<"8";
cout << endl;
}
else if(n%7==6){
cout << "6";
for (int i = 1; i <= n/7; i++)
cout<<"8";
cout<<endl;}
else if(n%7==0){
for (int i = 1; i <= n/7; i++)
cout<<"8";
cout<<endl;}
}
return 0;
}

View File

@@ -0,0 +1 @@
https://mp.weixin.qq.com/s/O2kcRCkM5PUhg4lDj4jGKQ