赞
踩
#include <iostream> #include <vector> #include <math.h> using namespace std; int main() { int m, n; while (cin >> m >> n) { vector<int> res; for (int i = m; i <= n; i++) { int tmp = i; int sum = 0; while (tmp != 0) { sum += pow(tmp % 10, 3); tmp = tmp / 10; } if (sum == i) { res.push_back(i); } } if (res.size() == 0) { cout << "no" << endl; } else { for (int i = 0; i < res.size(); i++) { cout << res[i] << " "; } cout << endl; } } return 0; }
#include<iostream> #include<string> using namespace std; int main() { int n; cin >> n; string str; for (int i = 0; i < n; i++) { cin >> str; int left = 0; int right = str.size() - 1; while (left < right) { if (str[left] == str[right]) { left++; right--; } else if ((str[left] == 'b' && str[right] == 'd') || (str[left] == 'd' && str[right] == 'b') || (str[left] == 'p' && str[right] == 'q') || (str[left] == 'q' && str[right] == 'p') || (str[left] == 'b' && str[right] == 'q') || (str[left] == 'q' && str[right] == 'b') || (str[left] == 'd' && str[right] == 'p') || (str[left] == 'p' && str[right] == 'd') || (str[left] == 'n' && str[right] == 'u') || (str[left] == 'u' && str[right] == 'n')) { left++; right--; } else if (str[left] == 'w' && str[right] == 'v') { str[left] = 'v'; left++; str.insert(str.begin() + left, 'v'); // right 不需要减了 } else if (str[left] == 'm' && str[right] == 'n') { str[left] = 'n'; left++; str.insert(str.begin() + left, 'n'); // right 不需要减了 } else if (str[left] == 'v' && str[right] == 'w') { str[right] = 'v'; str.insert(str.begin() + right, 'v'); //right 不需要减了 left++; } else if (str[left] == 'n' && str[right] == 'm') { str[right] = 'n'; str.insert(str.begin() + right, 'n'); //right 不需要减了 left++; } else { cout << "NO" << endl; break; } } if (left >= right) cout << "YES" << endl; } return 0; }
#include<iostream> #include<vector> using namespace std; struct Node { int attractId; int transportTime; }; int main() { int n, m, k; cin >> n >> m >> k; vector<int> attractVal(n); for (int i = 0; i < n; i++) { cin >> attractVal[i]; } vector<int> visitTime(n); for (int i = 0; i < n; i++) { cin >> visitTime[i]; } vector<vector<Node>> nodesTime(n, vector<Node>()); int u, v, w; for (int i = 0; i < m; i++) { cin >> u >> v >> w; Node node; node.attractId = v; node.transportTime = w; nodesTime[u].push_back(node); } int maxVal = -1; for (int i = 0; i < n; i++) { int sumTime = 0; sumTime += visitTime[i]; if (sumTime > k) { sumTime -= visitTime[i]; continue; } for (int j = 0; j < nodesTime[i].size(); j++) { sumTime += nodesTime[i][j].transportTime; sumTime += visitTime[nodesTime[i][j].attractId]; if (sumTime > k) { sumTime -= nodesTime[i][j].transportTime; sumTime -= visitTime[nodesTime[i][j].attractId]; continue; } for (int p = 0; p < nodesTime[nodesTime[i][j].attractId].size(); p++) { sumTime += nodesTime[nodesTime[i][j].attractId][p].transportTime; sumTime += visitTime[nodesTime[nodesTime[i][j].attractId][p].attractId]; if (sumTime > k) { sumTime -= nodesTime[nodesTime[i][j].attractId][p].transportTime; sumTime -= visitTime[nodesTime[nodesTime[i][j].attractId][p].attractId]; continue; } else { int curVal = attractVal[i] + attractVal[nodesTime[i][j].attractId] + attractVal[nodesTime[nodesTime[i][j].attractId][p].attractId]; if (curVal > maxVal) { maxVal = curVal; } } sumTime -= nodesTime[nodesTime[i][j].attractId][p].transportTime; sumTime -= visitTime[nodesTime[nodesTime[i][j].attractId][p].attractId]; } sumTime -= nodesTime[i][j].transportTime; sumTime -= visitTime[nodesTime[i][j].attractId]; } sumTime -= visitTime[i]; } cout << maxVal; return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。