- 团队
我们的聊天室-Our chat room( 将在2025年08月04日15:00:0弃用)
- 2025-7-20 15:59:47 @
都发条消息呀!!!
26 条评论
-
-
数字黑洞
#include <iostream> using namespace std; int main() { int N; cin >> N; // 输入一个三位数 int cnt = 0; while (N != 495) { int a = N / 100;// 百位数 int b = (N / 10) % 10;// 十位数 int c = N % 10;// 个位数 int maxnum = max (max(a,b), c); int minnum = min (min (a,b),c); int midnum = a+b+c-maxnum-minnum; N = maxnum*100+midnum*10+minnum - (minnum*100+midnum*10+maxnum); // it#=1 cnt++;// 增加变换次数 } cout << cnt << endl;// 输出变换饮效 return 0; }
-
2025-8-4 10:07:39@
数位之和
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ int a; cin>>a; bool flag=0;//假设没有满足条件的x和y for(int x=1;x*x<a;x++){//枚举x int y=sqrt (a-x*x);// if(x*x+y*y==a){//满足条件 flag=1;//标记满足 break; } } if (flag==1){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } } return 0; }
-
2025-7-24 10:15:23@
编程1:
#include <iostream> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> people(n); for (int i = 0; i < n; ++i) { people[i] = i + 1; } vector<int> result; int pos = 0; while (!people.empty()) { pos = (pos + m - 1) % people.size(); result.push_back(people[pos]); people.erase(people.begin() + pos); } for (int num : result) { cout << num << " "; } cout << endl; return 0; }
-
#include #include #include #include <windows.h> #include <conio.h> #include #include #include
using namespace std;
// 控制台颜色代码 enum ConsoleColor { BLACK = 0, BLUE = 1, GREEN = 2, CYAN = 3, RED = 4, MAGENTA = 5, YELLOW = 6, WHITE = 7, GRAY = 8, LIGHT_BLUE = 9, LIGHT_GREEN = 10, LIGHT_CYAN = 11, LIGHT_RED = 12, LIGHT_MAGENTA = 13, LIGHT_YELLOW = 14, BRIGHT_WHITE = 15 };
// 设置控制台颜色 void setColor(int color) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color); }
// 角色类 class Character { private: string name; int hp; int maxHp; int atk; string element; string specialSkill; string weapon;
public: Character(string n, int h, int a, string e, string s, string w = "无锋剑") : name(n), maxHp(h), hp(h), atk(a), element(e), specialSkill(s), weapon(w) {}
string getName() const { return name; } int getHp() const { return hp; } int getMaxHp() const { return maxHp; } int getAtk() const { return atk; } string getElement() const { return element; } string getSkill() const { return specialSkill; } string getWeapon() const { return weapon; } void takeDamage(int damage) { hp -= damage; if(hp < 0) hp = 0; } void heal(int amount) { hp += amount; if(hp > maxHp) hp = maxHp; } void upgradeWeapon() { if (weapon == "无锋剑") { weapon = "银剑"; atk += 5; } else if (weapon == "银剑") { weapon = "天空之刃"; atk += 10; } } bool isAlive() const { return hp > 0; } void displayStatus() const { cout << "[" << name << "]"; cout << " HP: " << hp << "/" << maxHp; cout << " ATK: " << atk; cout << " 元素: " << element; cout << " 武器: " << weapon << endl; cout << "元素战技: " << specialSkill << endl; }
};
// 敌人类 class Enemy { private: string name; int hp; int maxHp; int atk; string element;
public: Enemy(string n, int h, int a, string e) : name(n), maxHp(h), hp(h), atk(a), element(e) {}
string getName() const { return name; } int getHp() const { return hp; } int getMaxHp() const { return maxHp; } int getAtk() const { return atk; } string getElement() const { return element; } void takeDamage(int damage) { hp -= damage; if(hp < 0) hp = 0; } bool isAlive() const { return hp > 0; } void displayStatus() const { cout << "[" << name << "]"; cout << " HP: " << hp << "/" << maxHp; cout << " ATK: " << atk; cout << " 元素: " << element << endl; }
};
// 物品类 class Item { private: string name; string description; int value;
public: Item(string n, string d, int v) : name(n), description(d), value(v) {}
string getName() const { return name; } string getDesc() const { return description; } int getValue() const { return value; } void use(Character& character) const { if (name == "苹果") character.heal(20); else if (name == "甜甜花酿鸡") character.heal(50); else if (name == "提瓦特煎蛋") character.heal(30); else if (name == "武器强化卷") character.upgradeWeapon(); }
};
// 游戏类 class GenshinGame { private: vector characters; vector enemies; vector items; int primogems; int selectedCharacterIndex;
public: GenshinGame() : primogems(0), selectedCharacterIndex(-1) { // 初始化角色 characters.push_back(Character("旅行者", 120, 25, "风", "风涡剑", "无锋剑")); characters.push_back(Character("安柏", 90, 30, "火", "爆弹玩偶", "猎弓")); characters.push_back(Character("凯亚", 150, 22, "冰", "凛冽轮舞", "冷刃")); characters.push_back(Character("丽莎", 80, 35, "雷", "苍雷", "魔导绪论"));
// 初始化敌人 enemies.push_back(Enemy("水史莱姆", 60, 12, "水")); enemies.push_back(Enemy("火斧丘丘人", 80, 18, "火")); enemies.push_back(Enemy("冰深渊法师", 100, 15, "冰")); enemies.push_back(Enemy("雷莹术士", 120, 25, "雷")); enemies.push_back(Enemy("遗迹守卫", 200, 30, "无")); // 初始化物品 items.push_back(Item("苹果", "恢复20点生命值", 20)); items.push_back(Item("甜甜花酿鸡", "恢复50点生命值", 50)); items.push_back(Item("提瓦特煎蛋", "恢复30点生命值", 30)); items.push_back(Item("原石", "用于祈愿获取角色", 0)); items.push_back(Item("武器强化卷", "强化当前武器", 0)); // 初始原石 primogems = 160; } Character& getCurrentCharacter() { // 确保索引有效 if (selectedCharacterIndex < 0 || selectedCharacterIndex >= (int)characters.size()) { // 设置第一个角色为默认角色 selectedCharacterIndex = 0; } return characters[selectedCharacterIndex]; } void displayHeader(const string& title) { system("cls"); setColor(LIGHT_BLUE); cout << "*********************************************\n"; cout << "* 原神·控制台版 *\n"; cout << "*********************************************\n"; setColor(LIGHT_YELLOW); cout << ">> " << title << "\n"; setColor(WHITE); cout << "---------------------------------------------\n"; } void displayCharacters() { setColor(LIGHT_CYAN); cout << "============== 选择角色 ==============\n"; setColor(WHITE); for (size_t i = 0; i < characters.size(); i++) { cout << "[" << i+1 << "] "; setColor(LIGHT_GREEN); cout << setw(8) << left << characters[i].getName(); setColor(WHITE); cout << " | 生命: " << characters[i].getMaxHp(); cout << " 攻击: " << characters[i].getAtk(); cout << " 元素: " << characters[i].getElement(); cout << " 武器: " << characters[i].getWeapon() << endl; } setColor(GRAY); cout << "原石: " << primogems << endl; setColor(WHITE); } void selectCharacter() { while (true) { displayHeader("选择你的冒险伙伴"); displayCharacters(); cout << "\n输入角色编号(1-" << characters.size() << "): "; int choice; cin >> choice; if (choice > 0 && choice <= (int)characters.size()) { selectedCharacterIndex = choice - 1; setColor(LIGHT_GREEN); cout << "\n已选择: " << characters[selectedCharacterIndex].getName() << "!"; setColor(WHITE); system("pause"); return; } setColor(LIGHT_RED); cout << "无效的选择,请重新输入!\n"; setColor(WHITE); system("pause"); } } Enemy& getRandomEnemy() { return enemies[rand() % enemies.size()]; } void applyElementReaction(Character& c, Enemy& e) { string charElement = c.getElement(); string enemyElement = e.getElement(); int damage = c.getAtk(); setColor(LIGHT_MAGENTA); if (charElement == "火" && enemyElement == "冰") { cout << "??? 融化反应!伤害翻倍!\n"; damage *= 2; } else if (charElement == "冰" && enemyElement == "火") { cout << "??? 融化反应!伤害提升!\n"; damage = damage * 3 / 2; } else if (charElement == "火" && enemyElement == "水") { cout << "???? 蒸发反应!伤害翻倍!\n"; damage *= 2; } else if (charElement == "水" && enemyElement == "火") { cout << "???? 蒸发反应!伤害提升!\n"; damage = damage * 3 / 2; } else if (charElement == "水" && enemyElement == "雷") { cout << "??? 感电反应!持续伤害!\n"; damage += 15; } else if (charElement == "雷" && enemyElement == "水") { cout << "??? 感电反应!持续伤害!\n"; damage += 15; } else if (charElement == "风" && enemyElement != "无") { cout << "??? 扩散反应!附加" << enemyElement << "伤害!\n"; damage += 10; } else { cout << "普通攻击!\n"; } e.takeDamage(damage); setColor(LIGHT_YELLOW); cout << c.getName() << " 对 " << e.getName() << " 造成了 " << damage << " 点伤害!\n"; setColor(WHITE); } bool battle() { Character& player = getCurrentCharacter(); Enemy& enemy = getRandomEnemy(); int round = 1; while (true) { displayHeader("战斗:" + enemy.getName()); // 显示状态 setColor(LIGHT_GREEN); player.displayStatus(); setColor(LIGHT_RED); enemy.displayStatus(); setColor(WHITE); // 玩家选择 cout << "\n===== 第 " << round << " 回合 =====\n"; cout << "1. 普通攻击\n"; cout << "2. 元素战技 (" << player.getSkill() << ")\n"; cout << "3. 使用物品\n"; cout << "4. 逃跑\n"; int choice; cout << "选择行动: "; cin >> choice; // 玩家行动 switch (choice) { case 1: // 普通攻击 applyElementReaction(player, enemy); break; case 2: // 元素战技 setColor(LIGHT_CYAN); cout << player.getName() << " 使用了 " << player.getSkill() << "!\n"; applyElementReaction(player, enemy); break; case 3: // 使用物品 if (useItem(player)) { setColor(LIGHT_GREEN); cout << "使用了物品,恢复了生命值!\n"; } else { setColor(LIGHT_RED); cout << "物品使用失败,失去本回合!\n"; } break; case 4: // 逃跑 setColor(LIGHT_MAGENTA); if (rand() % 3 == 0) { cout << "逃跑成功!\n"; return true; } cout << "逃跑失败!\n"; break; default: setColor(LIGHT_RED); cout << "无效的选择!失去本回合!\n"; break; } setColor(WHITE); // 检查敌人是否被击败 if (!enemy.isAlive()) { setColor(LIGHT_YELLOW); cout << "\n胜利!你击败了 " << enemy.getName() << "!\n"; primogems += 50; cout << "获得50原石!总原石: " << primogems << endl; setColor(WHITE); system("pause"); return true; } // 敌人攻击 setColor(LIGHT_RED); player.takeDamage(enemy.getAtk()); cout << enemy.getName() << " 对 " << player.getName() << " 造成了 " << enemy.getAtk() << " 点伤害!\n"; setColor(WHITE); // 检查玩家是否存活 if (!player.isAlive()) { setColor(LIGHT_RED); cout << player.getName() << " 倒下了...游戏结束\n"; setColor(WHITE); system("pause"); return false; } round++; system("pause"); } } bool useItem(Character& player) { setColor(LIGHT_GREEN); cout << "===== 物品列表 =====\n"; for (size_t i = 0; i < items.size(); i++) { cout << i+1 << ". " << items[i].getName() << " - " << items[i].getDesc() << endl; } int choice; cout << "选择物品: "; cin >> choice; if (choice > 0 && choice <= (int)items.size()) { items[choice-1].use(player); return true; } return false; } void explore() { Character& player = getCurrentCharacter(); displayHeader("探索提瓦特大陆"); setColor(LIGHT_GREEN); player.displayStatus(); setColor(WHITE); cout << "\n1. 蒙德城(自由之都)\n"; cout << "2. 璃月港(契约之城)\n"; cout << "3. 稻妻城(永恒之城)\n"; cout << "4. 须弥城(智慧之城)\n"; cout << "5. 返回主菜单\n"; int choice; cout << "选择探索区域: "; cin >> choice; if (choice == 5) return; string regionName; switch(choice) { case 1: regionName = "蒙德城"; break; case 2: regionName = "璃月港"; break; case 3: regionName = "稻妻城"; break; case 4: regionName = "须弥城"; break; default: regionName = "未知区域"; } setColor(LIGHT_CYAN); cout << "\n>> 前往" << regionName << "探险\n"; setColor(WHITE); // 随机事件 int event = rand() % 100; if (event < 40) { // 40%几率遇到敌人 setColor(LIGHT_RED); cout << "遭遇了敌人!\n"; setColor(WHITE); if (!battle()) { return; // 战斗失败退出 } } else if (event < 70) { // 30%几率找到宝箱 setColor(LIGHT_YELLOW); cout << "发现了一个宝箱!\n"; primogems += 20; player.heal(30); cout << "获得20原石和30点生命值恢复!\n"; cout << "当前原石: " << primogems << endl; setColor(WHITE); } else if (event < 85) { // 15%几率遇到神像 setColor(LIGHT_CYAN); cout << "遇到了七天神像!\n"; player.heal(player.getMaxHp()); cout << "生命值完全恢复!\n"; setColor(WHITE); } else { // 15%几率什么都没发生 setColor(GRAY); cout << "探索了一段时间,但没发现特别的东西...\n"; setColor(WHITE); } system("pause"); explore(); // 继续探索 } void wish() { displayHeader("祈愿"); setColor(LIGHT_YELLOW); cout << "====== 祈愿系统 ======\n"; cout << "1. 祈愿一次 (160原石)\n"; cout << "2. 祈愿十次 (1600原石)\n"; cout << "3. 返回主菜单\n\n"; cout << "当前原石: " << primogems << endl; setColor(WHITE); int choice; cout << "选择祈愿类型: "; cin >> choice; if (choice == 1 && primogems >= 160) { primogems -= 160; wishAnimation(); // 90%获得物品,10%获得角色 if (rand() % 10 < 9) { vector<string> itemsName; itemsName.push_back("苹果"); itemsName.push_back("甜甜花酿鸡"); itemsName.push_back("提瓦特煎蛋"); itemsName.push_back("原石"); itemsName.push_back("武器强化卷"); Item item(itemsName[rand() % itemsName.size()], "随机物品", 0); setColor(LIGHT_MAGENTA); cout << "获得了物品: " << item.getName() << "!\n"; setColor(WHITE); } else { vector<string> charNames; charNames.push_back("神里绫华"); charNames.push_back("魈"); charNames.push_back("凝光"); charNames.push_back("北斗"); vector<string> elements; elements.push_back("冰"); elements.push_back("风"); elements.push_back("岩"); elements.push_back("雷"); Character newChar(charNames[rand() % charNames.size()], rand() % 50 + 70, rand() % 20 + 20, elements[rand() % elements.size()], "新技能", "新武器"); characters.push_back(newChar); setColor(LIGHT_GREEN); cout << "★ 获得了新角色: " << newChar.getName() << "! ★\n"; setColor(WHITE); } } else if (choice == 2 && primogems >= 1600) { primogems -= 1600; for (int i = 0; i < 10; i++) { wishAnimation(); if (rand() % 10 < 9) { vector<string> itemsName; itemsName.push_back("苹果"); itemsName.push_back("甜甜花酿鸡"); itemsName.push_back("提瓦特煎蛋"); itemsName.push_back("原石"); itemsName.push_back("武器强化卷"); Item item(itemsName[rand() % itemsName.size()], "随机物品", 0); setColor(LIGHT_MAGENTA); cout << "获得了物品: " << item.getName() << "!\n"; setColor(WHITE); } else { vector<string> charNames; charNames.push_back("神里绫华"); charNames.push_back("魈"); charNames.push_back("凝光"); charNames.push_back("北斗"); vector<string> elements; elements.push_back("冰"); elements.push_back("风"); elements.push_back("岩"); elements.push_back("雷"); Character newChar(charNames[rand() % charNames.size()], rand() % 50 + 70, rand() % 20 + 20, elements[rand() % elements.size()], "新技能", "新武器"); characters.push_back(newChar); setColor(LIGHT_GREEN); cout << "★ 获得了新角色: " << newChar.getName() << "! ★\n"; setColor(WHITE); } Sleep(300); } setColor(LIGHT_YELLOW); cout << "祈愿十次完成!\n"; } else { if (primogems < 160) { setColor(LIGHT_RED); cout << "原石不足!\n"; } setColor(WHITE); } system("pause"); } void wishAnimation() { setColor(LIGHT_YELLOW); cout << "★"; Sleep(100); cout << "★"; Sleep(100); cout << "★"; Sleep(100); setColor(LIGHT_MAGENTA); cout << "祈"; Sleep(100); cout << "愿"; Sleep(100); cout << "中"; Sleep(100); setColor(LIGHT_BLUE); cout << "★"; Sleep(100); cout << "★"; Sleep(100); cout << "★" << endl; setColor(WHITE); } void displayCharacterStatus() { displayHeader("角色状态"); setColor(LIGHT_GREEN); getCurrentCharacter().displayStatus(); setColor(WHITE); // 显示所有角色 setColor(LIGHT_CYAN); cout << "\n===== 所有角色 =====" << endl; for (size_t i = 0; i < characters.size(); i++) { setColor((i % 6) + 9); cout << "[" << i+1 << "] " << characters[i].getName(); cout << " (" << characters[i].getElement() << ")"; cout << " HP: " << characters[i].getHp() << "/" << characters[i].getMaxHp(); cout << endl; } setColor(WHITE); } void start() { srand(time(NULL)); // 解决中文乱码问题 SetConsoleOutputCP(936); // GB2312编码 SetConsoleCP(936); // 设置控制台大小 system("mode con cols=80 lines=30"); while (true) { displayHeader("主菜单"); cout << "1. 选择角色\n"; cout << "2. 开始冒险\n"; cout << "3. 祈愿\n"; cout << "4. 角色状态\n"; cout << "5. 退出游戏\n\n"; if (selectedCharacterIndex != -1) { setColor(LIGHT_GREEN); cout << "当前角色: " << getCurrentCharacter().getName() << "\n"; setColor(WHITE); } else { setColor(LIGHT_RED); cout << "尚未选择角色\n"; setColor(WHITE); } setColor(LIGHT_YELLOW); cout << "原石: " << primogems << endl; setColor(WHITE); int choice; cout << "请选择: "; cin >> choice; if (selectedCharacterIndex == -1 && choice > 1 && choice < 5) { setColor(LIGHT_RED); cout << "请先选择角色!\n"; setColor(WHITE); system("pause"); continue; } switch (choice) { case 1: selectCharacter(); break; case 2: explore(); break; case 3: wish(); break; case 4: displayCharacterStatus(); system("pause"); break; case 5: return; default: setColor(LIGHT_RED); cout << "无效的选择!\n"; setColor(WHITE); break; } } }
};
int main() { GenshinGame game; game.start(); return 0; }
-
#include<bits/std.c++.h> using namespace std;
// 马的8种移动方向(“日”字形) const int dx[] = {1, 2, 2, 1, -1, -2, -2, -1};//改成田的 const int dy[] = {2, 1, -1, -2, -2, -1, 1, 2};
int sum = 0;
void dfs(int x, int y, int n, int m, vector<vector<1️⃣>>& visited, int steps) { if (steps == n * m) { sum++; return; }
for (int i = 0; i < 8; ++i) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx >= 0 && nx < n && ny >= 0 && ny < m && !visited[nx][ny]) { visited[nx][ny] = true; dfs(nx, ny, n, m, visited, steps + 1); visited[nx][ny] = false; // 回溯 } }
}
int main() { int T; cin >> T;
while (T--) { int n, m, x, y; cin >> n >> m >> x >> y; vector<vector<bool>> visited(n, vector<bool>(m, false)); visited[x][y] = true; // 标记起点 sum = 0; dfs(x, y, n, m, visited, 1); // 初始步数为1(起点已访问) cout << sum << endl; } return 0;
}
1️⃣:bool
-
填空题答案
第一题:瓷砖问题
第1题 (1)处
@
(因为题目说明'@'表示初始位置)第2题 (2)处
vis[sx][sy] = 1
(标记初始位置已访问)第3题 (3)处
vis[nx][ny] == 0
(检查该位置未被访问过)第4题 (4)处
mp[nx][ny] == '.' || mp[nx][ny] == '@'
(检查是黑色瓷砖或初始位置)第5题 (5)处
ans++
(每访问一个新位置,计数器加1)第二题:棋盘寻宝
第6题 (1)处
node
(队列中存储的是节点结构体)第7题 (2)处
mp[1][1] == '#'
(检查起点是否是守卫)第8题 (3)处
!q.empty()
(队列不为空时继续循环)第9题 (4)处
node r = {nx, ny};
(创建新节点准备入队)第10题 (5)处
cout << "NO";
(如果队列为空仍未找到宝藏,输出NO) -
-
#include<bits/stdc++.h> using namespace std; int n,m; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; struct node{ int x,y; }; queueq; char mp[101][101]; int vis[101][101]; void bfs(){ node a={1,1}; vis[1][1]=1; q.push(a); while(q.empty()!=1){ node f=q.front(); if(mp[f.x][f.y]'*'){ cout<<"YES"; return; } if(mp[1][1]'#'){ cout<<"NO"; return; } for(int i=0;i<4;i++){ char nx=f.x+dx[i]; char ny=f.y+dy[i]; if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&vis[nx][ny]==0&&mp[nx][ny]!='#'){ vis[nx][ny]=1; node b={nx,ny}; q.push(b); } } q.pop(); } cout<<"NO"; } int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>mp[i][j]; } } bfs(); return 0; }
-
2025-7-20 16:50:07@
抢到首评
- 1