2017 BJ ICPC 石子合并变种 向量基本功及分类考察
E
模拟
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 1e9 //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation int cat[105]; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que; int main() { int m, n, x; while (cin >> m >> n >> x) { int anser1 = m; int anser2 = 0; for (int i = 1; i <= n; i++) { scanf("%d", &cat[i]); que.push(make_pair(0, cat[i])); } while (!que.empty()) { pair<int, int> cnt = que.top(); if (cnt.first >= x) { que.pop(); continue; } else { que.pop(); if (anser1 > 0) { cnt.first += cnt.second; if (cnt.first <= x) { anser1--; } else { anser1--; anser2++; } que.push(cnt); } } } cout << anser1 << " " << anser2 << endl; } }
F
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 1e9 //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation char f[105][105]; char ans[100005]; char anser[105][105]; int pop = 0; int dx, dy; int dir; int n; bool check(int x, int y) { if (x > n || x < 1) { return false; } if (y > n || y < 1) { return false; } if (anser[x][y] != '.') { return false; } return true; } int main() { while (cin >> n) { for (int i = 1; i <= 100; i++) { for (int j = 1; j <= 100; j++) { anser[i][j] = '.'; } } dir = 0; dx = dy = 1; pop = 0; for (int i = 1; i <= n; i++) { scanf("%s", f[i] + 1); } for (int i = 2; i <= n + 1; i++) { if (i % 2 == 0) { for (int j = i - 1; j >= 1; j--) { ans[++pop] = f[j][i - j]; } } else { for (int j = 1; j <= i - 1; j++) { ans[++pop] = f[j][i - j]; } } } for (int i = n + 2; i <= 2 * n; i++) { if (i % 2 == 0) { for (int j = n; j >= i - n; j--) { ans[++pop] = f[j][i - j]; } } else { for (int j = i - n; j <= n; j++) { ans[++pop] = f[j][i - j]; } } } // for (int i = 1; i <= pop; i++) // { // cout << ans[i]; // } // cout << endl; for (int i = 1; i <= pop; i++) { //cout<<dx<<" "<<dy<<endl; anser[dx][dy] = ans[i]; if (!check(dx + turn[dir][0], dy + turn[dir][1])) { dir = (dir + 1) % 4; } dx = dx + turn[dir][0]; dy = dy + turn[dir][1]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cout << anser[i][j]; } cout << endl; } } }
J
石子合并 不过合并的范围由2变为L-R(2<=L<=R<=N) 问你最少的花费是多少