矩阵重塑(其一)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m,p,q;
cin >> n >> m >> p >> q;
vector<int> vec(n * m);
vector<vector<int>> res(p, vector(q,0));
int k = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> vec[k++];
}
}
k = 0;
for(int i = 0; i < p; i++){
for(int j = 0; j < q; j++){
res[i][j] = vec[k++];
}
}
for(int i = 0; i < p; i++){
for(int j = 0; j < q; j++){
cout << res[i][j] << " ";
}
cout << endl;
}
return 0;
}
矩阵重塑(其二)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m,t;
cin >> n >> m >> t;
vector<vector<int>> res(10000, vector<int>(10000,0));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> res[i][j];
}
}
int k = 0;
vector<int> one(n * m);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
one[k++] = res[i][j];
}
}
for(int i = 0; i < t; i++){
int op,a,b;
cin >> op >> a >> b;
if(op == 1){
k = 0;
n = a,m = b;
for(int l = 0; l < n; l++){
for(int j = 0; j < m; j++){
res[l][j] = one[k++];
}
}
k = 0;
for(int l = 0; l < n; l++){
for(int j = 0; j < m; j++){
one[k++] = res[l][j];
}
}
}else if(op == 2){
k = 0;
swap(n,m);
for(int l = 0; l < m; l++){
for(int j = 0; j < n; j++){
res[j][l] = one[k++];
}
}
k = 0;
for(int l = 0; l < n; l++){
for(int j = 0; j < m; j++){
one[k++] = res[l][j];
}
}
}else if(op == 3){
cout << res[a][b] << endl;
}
}
return 0;
}
文本分词
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin >> n >> m;
unordered_map<string,int> mp;
set<string> st;
unordered_map<string,int> mmp;
for(int i = 0; i < n; i++){
string s;
int f;
cin >> s >> f;
mp[s] = f;
for(int j = 0; j < s.size(); j++){
st.insert(string(1,s[j]));
if(j != s.size() - 1){
string str = string(1,s[j]) + "-" + string(1,s[j+1]);
mmp[str] += f;
}
}
}
int maxx = 0;
string str;
for(auto it : mmp){
if(maxx < it.second){
maxx = it.second;
str = it.first;
}
}
str.erase(str.find('-'),1);
for(auto c : st){
cout << c << endl;
m--;
if(m <= 0)
break;
}
if(m > 0)
cout << str << endl;
return 0;
}
货物调度
#include <bits/stdc++.h>
using namespace std;
int res = INT_MAX;
int n,m,v;
vector<pair<int,int>> warehouse(1001);//基本费用 计件费用
vector<pair<int,int>> goods(1001);//现金 仓库号
unordered_set<int> path;//记录从几号仓库出货
void backtracking(int cash,int cost,int index){
if(cost >= res)
return;
if(cash - cost >= v){
res = min(res, cost);
return;
}
for(int i = index; i < m; i++){
int id = goods[i].second;//仓库号
if(path.find(id) == path.end()){
path.insert(id);
backtracking(cash + goods[i].first, cost + warehouse[id].first + warehouse[id].second,i + 1);
path.erase(id);
}else{
backtracking(cash + goods[i].first, cost + warehouse[id].second,i + 1);
}
}
}
int main() {
cin >> n >> m >> v;
for(int i = 0; i < n; i++){
cin >> warehouse[i].first >> warehouse[i].second;
}
for(int i = 0; i < m; i++){
cin >> goods[i].first >> goods[i].second;
}
backtracking(0,0,0);
cout << res;
return 0;
}
哥德尔机
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
vector<vector<int>> V(10000,vector<int>(10000, 0));
cin >> n >> m;
int x1,x2,y1,y2,v;
for(int i = 0; i < n; i++){
cin >> x1 >> x2 >> y1 >> y2 >> v;
for(int j = x1; j <= x2; j++){
for(int k = y1; k <= y2; k++){
V[j][k] = v + max(V[j][k] - v, 0);
}
}
}
for(int i = 0; i < m; i++){
cin >> x1 >> x2 >> y1 >> y2;
int res = 0;
for(int j = x1; j <= x2; j++){
for(int k = y1; k <= y2; k++){
res = max(res, V[j][k]);
}
}
cout << res << endl;
}
return 0;
}
最后得分