赞
踩
#include <iostream> typedef long long LL; using namespace std; int a[30]; //转八进制 LL f(LL m) { LL sum = 0, n = 0; while(m) { a[++ n] = m % 8; m /= 8; } for(int i = n; i >= 1; i --) sum = sum * 10 + a[i]; return sum; } //数字反转 LL r(LL m) { LL sum = 0; while(m) { sum = sum * 10 + m % 10; m /= 10; } return sum; } int main() { int n; cin >> n; //枚举平方根 for(int i = 1; i <= n / i; i ++) { LL m = f(i * i); if(m == r(m)) cout << i * i << " "; } }
#include <iostream> #include <cstring> #include <unordered_map> using namespace std; const int N = 1e6 + 10; int a[N]; int main() { int n; scanf("%d", &n); unordered_map<int, int> h; for(int i = 0; i < n; i ++) { scanf("%d", &a[i]); if(h.count(a[i])) h[a[i]] ++; else h[a[i]] = 1; } for(int i = 0; i < n; i ++) { if(h[a[i]] >= n / 2) { cout << a[i]; return 0; } } cout << "No"; return 0; }
#include <iostream> #include <unordered_map> #include <stack> using namespace std; stack<int> stk, op; void eval() { int b = stk.top(); stk.pop(); int a = stk.top(); stk.pop(); char p = op.top(); op.pop(); if(p == '+') stk.push(a + b); else if(p == '-') stk.push(a - b); else if(p == '*') stk.push(a * b); else if(p == '/') stk.push(a / b); } int main() { string s; getline(cin, s); //运算符优先级 unordered_map<char, int> pr {{'+', 1}, {'-', 1}, {'*', 2}, {'/', 2}}; for(int i = 0; i < s.size(); i ++) { if(s[i] == ' ') continue; else if(isdigit(s[i])) { int j = i, x = 0; while(isdigit(s[j])) x = x * 10 + s[j ++] - '0'; stk.push(x); i = j - 1; } else { //计算栈中优先级大于等于当前运算符 while(!op.empty() && pr[op.top()] >= pr[s[i]]) eval(); op.push(s[i]); } } while(!op.empty()) eval(); cout << stk.top(); return 0; }
#include <iostream> using namespace std; char g[100][100]; //sum[x]表示x字符的出现总数,row[i][x]表示第i行中x字符有没有出现过 //col[i][x]表示第i列中x字符有没有出现过 //f[i][x]表示第i个大格子中x字符有没有出现过 int sum[150], row[10][150], col[10][150], f[10][150]; int check(int i, int j, char x) { if(sum[x] > 8) return 0; if(row[i][x]) return 0; if(col[j][x]) return 0; // i / 3 * 3 + j / 3; 大格子 if(f[i / 3 * 3 + j / 3][x]) return 0; return 1; } void dfs(int n) { if(n > 80) { for(int i = 0; i < 9; i ++) { for(int j = 0; j < 9; j ++) cout << g[i][j]; cout << endl; } exit(0); } int i = n / 9, j = n % 9; //i行j列 //已经填过数了 if(g[i][j] != '.') { dfs(n + 1); return ; } //枚举该位置可以填的数 for(int x = '1'; x <= '9'; x ++) { if(!check(i, j, x)) continue; g[i][j] = x; sum[x] ++; row[i][x] = 1; col[j][x] = 1; f[i / 3 * 3 + j / 3][x] = 1; dfs(n + 1); g[i][j] = '.'; sum[x] --; row[i][x] = 0; col[j][x] = 0; f[i / 3 * 3 + j / 3][x] = 0; } } int main() { char x; for(int i = 0; i < 9; i ++) { for(int j = 0; j < 9; j ++) { cin >> x; g[i][j] = x; sum[x] ++; row[i][x] = 1; col[j][x] = 1; f[i / 3 * 3 + j / 3][x] = 1; } } dfs(0); return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。