2050 cf比赛 传送门
A Sum of 2050 standard input/output 1 s, 256 MB Submit Add to favourites x16113
//可以直接暴力数组枚举 也可以 一步步算出来
B Morning Joggingstandard input/output 1 s, 256 MB Submit Add to favourites x8733
//其实就是n*m 的矩阵, 需要把每一列的最小值相加最小, 做法是把所有的数排个序, 然后按从小到大 放在相应的列上, 其他数就随便放 用一个多元组 tuple存每个数的大小和行列位置, 然后只按大小排序 接着前m个数放在不同的列上(t神真强
C Fillomino 2 standard input/output 1 s, 256 MB Submit Add to favourites x7570
//开始想半天不会, 然后看了t神做法, 直接把每个数 一直往左边放 放不下了就往下放 然后再往左边放 可以证明这个是有效的
D Explorer Space standard input/output 2 s, 256 MB Submit Add to favourites x4122
直接暴力搜索每个点的最小k/2路径和, dp记录下( O(nmk)
#include <bits/stdc++.h> using namespace std; #define _for(i,a,b) for(int i = (a); i < (b); i++) #define _rep(i,a,b) for(int i = (a); i <= (b); i++) #define all(v) (v).begin(), (v).end() #define nl " " #define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin()) #define sz(v) ((int)(v).size()) //#define LOCAL typedef long double ld; typedef long long ll; typedef unsigned long long ull; #ifdef LOCAL //#include "pretty_print.h" #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__) #else #define dbg(...) 42 #endif template <typename T> T sqr(T x) { return x * x; } template <typename T> T abs(T x) { return x < 0? -x : x; } template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; } template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; } template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; } auto random_address = [] { char *p = new char; delete p; return (uint64_t) p; }; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1)); mt19937_64 rngll(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1));
void taskA() { int t; cin >> t; while(t--) { ll n; cin >> n; if(n%2050 != 0) { cout << "-1 "; continue; } n /= 2050; int ans = 0; while(n != 0) { ans += (n%10); n /= 10; } cout << ans << " "; } return; } void taskA1() { int t; cin >> t; while(t--) { ll a[] = { 2050, 20500, 205000, 2050000, 20500000, 205000000, 2050000000, 20500000000, 205000000000, 2050000000000, 20500000000000, 205000000000000, 2050000000000000, 20500000000000000, 205000000000000000 }; ll n; cin >> n; int f = 0; ll ans = 0; while(1) { if(n == 0) break; else if(n < a[0]) { cout << "-1 "; f = 1; break; } else { for(int i = 14; i >= 0; i--) if(n >= a[i]) ans += (n/a[i]), n = n%a[i]; } } if(!f) cout << ans << " "; } return; }
void taskB() { int t; cin >> t; while(t--) { int h, w; cin >> h >> w; vector<vector<int>> a(h, vector<int>(w)); vector<vector<int>> b(h, vector<int>(w, -1)); vector<tuple<int, int, int> > tem; _for(i,0,h) _for(j,0,w) cin >> a[i][j], tem.emplace_back(a[i][j], i, j); sort(all(tem)); _for(j,0,w) { int i = get<1>(tem[j]); b[i][j] = get<0>(tem[j]); } _for(x,w,h*w) { int i = get<1>(tem[x]); _for(j,0,w) if(b[i][j] == -1) { b[i][j] = get<0>(tem[x]); break; } } _for(i,0,h) { _for(j,0,w) { if(j != 0) cout << " "; cout << b[i][j]; } cout << " "; } } return; }
void taskC() { int n; cin >> n; vector<vector<int>> a(n, vector<int>(n, 0)); _for(i,0,n) cin >> a[i][i]; _for(i,0,n) { int tmp = a[i][i]-1; int x = i, y = i; while(tmp--) { if(y>0 and a[x][y-1] == 0) y--; else x++; a[x][y] = a[i][i]; } } _for(i,0,n) { _for(j,0,i+1) { if(j != 0) cout << " "; cout << a[i][j]; } cout << " "; } return ; }
void taskD() { int n,m,k; cin >> n >> m >> k; vector<vector<int> > row(n, vector<int> (m-1, 0)); vector<vector<int> > col(n-1, vector<int> (m, 0)); _for(i,0,n) _for(j,0,m-1) cin >> row[i][j]; _for(i,0,n-1) _for(j,0,m) cin >> col[i][j]; vector<vector<int> > ans(n, vector<int>(m, 0)); if(k%2 == 1) { ans.assign(n, vector<int>(m, -1)); } else { int N = (int)(1e9); vector<vector<int> > new_ans(n, vector<int>(m, 0)); _for(l,0,k/2) { _for(i,0,n) _for(j,0,m) { new_ans[i][j] = N; if(i > 0) new_ans[i][j] = min(ans[i-1][j]+2*col[i-1][j], new_ans[i][j]);//Down if(j > 0) new_ans[i][j] = min(ans[i][j-1]+2*row[i][j-1], new_ans[i][j]);//Right if(i < n-1) new_ans[i][j] = min(ans[i+1][j]+2*col[i][j], new_ans[i][j]);//Up if(j < m-1) new_ans[i][j] = min(ans[i][j+1]+2*row[i][j], new_ans[i][j]);//Left } swap(ans, new_ans); } } _for(i,0,n) { _for(j,0,m) { if(j > 0) cout << " "; cout << ans[i][j]; } cout << " "; } return; }
int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); taskD(); return 0; }