(1)晨跑
题目大意:
输入一个数为样例次数
再输入两个数n,m(n表示每条路的疲劳值,m表示有几个选手)
每个选手都需要跑过每条路,最后要使每条路的所有人的疲劳值的最小值相加最小,输出任意情况。
思路:
将最小的m个疲劳值排序,取m个,再将其排进去按0到m-1排过去
但是原本在哪一行的疲劳值不能去其他行,可以令其行不变但是其列的位置改变,使其成为那一列的最小值。
题目链接
下面引入一个概念(pair)
这个函数可以一开始便创建然后赋值
例如
#include <bits/stdc++.h>
usingnamespace std;
int main () {
pair <string,double> product1 ("tomatoes",3.25);
}
也可以先创建后面赋值
例如:
#include <bits/stdc++.h>
usingnamespace std;
int main () {
pair <string,double> product1 ;
product1 = make_pair ("shoes",20.0);
}
pair是一个类型跟int,double什么都是类型,所以可以放进map函数里。
代码如下:
注:此代码是莫哥的,这个方法很妙就记下了。
#include<bits/stdc++.h>
using namespace std;
#define MAX 0x3f3f3f3f
typedef long long ll;
#define bug(a) cout<<endl<<"*"<<a<<endl;
const int maxn = 105;
int ans[maxn][maxn];
int h[maxn];
struct node {
int v;
int idx;
} a[maxn * maxn];
bool cmp(node a, node b) {
return a.v < b.v;
}
int main()
{
int n, m, i, j, t;
cin >> t;
while (t--) {
memset(h, 0, sizeof(h));
cin >> n >> m;
int cnt = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
cin >> a[cnt].v;
a[cnt].idx = i;
cnt++;
}
}
sort(a, a + cnt, cmp);
map<pair<int, int >, int >mm;
for (i = 0; i < cnt; i++) {
if (i < m) {
ans[a[i].idx][i] = a[i].v;//细节就在这里,原本哪行放哪行,只是放的列不一样,因为要使每列元素最小
mm[make_pair(a[i].idx, i)]++;//将key(pair类型)赋值,赋值方法上面讲了
}
else {
for (j = 0; j < m; j++) {
if (mm[make_pair(a[i].idx, j)] == 0) {
ans[a[i].idx][j] = a[i].v;
mm[make_pair(a[i].idx, j)] = 1;
break;
}
}
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
cout << ans[i][j] << " ";
}
cout << endl;
}
}
return 0;
}
(2)找顺序
题目->cf_A题
直接给代码:
这题主要学方法和&的运用
#include<iostream>
#include<stack>
#include<string>
#include<algorithm>
#include<iomanip>
#include<fstream>
#include<string>
#include<map>
#include<stdlib.h>
#define bug(a) (cout<<"*"<<a<<endl)
#define bugg(a,b) (cout<<"*"<<a<<' '<<b<<endl)
#define buggg(a,b,c) (cout<<"*"<<a<<' '<<b<<' '<<c<<endl)
#define endl '\n'
#define MAX 0x3f3f3f
using namespace std;
typedef long long ll;
const int M = 100;
string arr[M];
char c[] = {'W','R'};
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n,i,t,m,j;
cin>>t;
while (t--) {
cin >> n>>m;
bool w[2] = { 0 }, r[2] = {0};
for (i = 0; i < n; i++) {
cin >> arr[i];
for (j = 0; j < m; j++) {
if (arr[i][j] == 'R')
{
r[(i + j) % 2] = true;
}
else if (arr[i][j] == 'W') {
w[(i + j) % 2] = true;
}
}
}
bool ans1, ans2;
ans1 = (r[0] || w[1]);
ans2 = (r[1] || w[0]);
/*bug(r[0]);
bug(r[1]);
bug(w[0]);
bug(w[1]);*/
if (ans1 && ans2) {
cout << "NO" << endl;
continue;
}
cout << "YES" << endl;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
char a = c[i + j + ans1 & 1];
cout << a;
}
cout << endl;
}
}
}
(3)未定