我们教练说5题省赛拿牌有希望,然后ACM校队一个大佬说至少要到6~7题才能拿铜。。。T_T
我A了四题,我队友A了五题,他把J题A了,我没在机房打比赛,所以我们队就不小心分成俩号交了,我J题没看懂,后来就没再写了。相当于我们队还是A了五道题,我队友可是大佬~贼强~哈哈哈~J题抽空补上,那就放一下我AC的四个题的题解:
< A >
链接:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5752
题意:
在一个序列里找一个绝对峰值,要求在该值以前的序列严格递增,该值以后严格递减。
思路:
首先你找的这个值,必须是最大值,然后找到最大值以后,再看他左右两端的单调性。注意如果该序列本身就类似单调,那不满足题意,本身类似单调意味着,最大值的位置在首位或末位。
本人AC代码:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int Maxx = 1e5 + 7;
const ll Inf = 2e9 + 128;
int cas;
int n;
ll a[Maxx];
int main() {
scanf("%d", &cas);
while(cas--) {
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
a[0] = 0;
ll maxT = -Inf;
int pos;
for(int i = 1; i <= n; i++) {
if(a[i] > maxT) {
maxT = a[i];
pos = i;
}
}
if(pos == 1 || pos == n) {
puts("No");
continue;
}
bool flg = 1;
for(int i = 1; i < pos; i++) {
if(a[i + 1] <= a[i]) {
flg = 0;
break;
}
}
for(int i = n; i > pos; i--) {
if(a[i - 1] <= a[i]) {
flg = 0;
break;
}
}
if(flg) puts("Yes");
else puts("No");
}
}
< B >
链接:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5753
题意:
给两段序列,在第一个序列每个元素上加上一个实数,使得该序列与第二个序列更相近,即相同位置对应的元素变多,求最多相似个数。
思路:
通过这题讲一下map的基本操作,所谓map,说白了,就是一个高端数组,是一个带属性的数组,声明方法为
map <int , int> mp;
意思是,一个int型的数组,它有一个int属性叫mp。
所以我就先开了一个t[ ]数组,记录 a[ i ] - b[ i ] 的值,即 t[ i ] = a[ i ] - b[ i ]; 这就记录了两个数组对应元素的差值,哪个值出现最多就选哪个呗~那么对于-1e9 ~ 1e9的数据,你总不能开个1e18长度的数组来记录吧?所以这时候mp属性就派上用场了,mp[ t[ i ] ]++, 就记录了每个差值出现了几次,用个max维护即可,注意要加头文件<map>, 且每次使用先要用mp.clear( )初始化。
本人AC代码:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
const int Maxx = 1e5 + 7;
int cas;
int n;
int a[Maxx];
int b[Maxx];
int t[Maxx];
map <int , int> mp;
int main() {
scanf("%d", &cas);
while(cas--) {
scanf("%d", &n);
memset(t, 0, sizeof(t));
mp.clear();
int maxT = -Maxx;
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
for(int i = 1; i <= n; i++) {
t[i] = b[i] - a[i];
mp[t[i]]++;
maxT = max(maxT, mp[t[i]]);
}
printf("%d\n", maxT);
}
}
< L >
链接:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5761
题意:
给一堆单词,每个单词后面有它的喜爱度,给定要选定的单词个数num, 要求你选出一串单词使得它们组成的句子,总喜爱度最高,总喜爱度sum = (t - i +1)*第i个单词的喜爱度,输出总喜爱度。如果有相同选法,选字典序最小那个句子输出。
思路:
赤裸裸的结构体快排,不多说,之前讲过结构体快排的专项,不懂的戳这里~
https://blog.csdn.net/EricGipsy/article/details/79922165
本人AC代码:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int Maxx = 1e5 + 7;
int cas;
int n, t;
struct PP {
char s[105];
ll m;
} per[Maxx];
bool cmp(PP x, PP y) {
if(x.m == y.m) {
if(strcmp(x.s, y.s) < 0) return strcmp(x.s, y.s);
}
return x.m > y.m;
}
int main() {
scanf("%d", &cas);
while(cas--) {
scanf("%d %d", &n, &t);
for(int i = 1; i <= n; i++) scanf("%s %lld", per[i].s, &per[i].m);
sort(per + 1, per + n + 1, cmp);
ll sum = 0;
for(int i = 1; i <= t; i++) sum += per[i].m * (t - i + 1);
printf("%lld ", sum);
for(int i = 1; i <= t; i++) {
if(i < t) printf("%s ", per[i].s);
else printf("%s\n", per[i].s);
}
}
return 0;
}
< M >
链接:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5762
题意:
水题,给一串序列,给一个数,让该序列每个元素加上该数,看能否被7整除。
思路:
直接按题意暴力。
本人AC代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long ll;
const int Maxx = 1e5 + 7;
const int Inf = 1e9 + 7;
int cas;
int n, m;
int a[Maxx];
int main() {
scanf("%d", &cas);
while(cas--) {
scanf("%d %d", &n, &m);
bool flg = 0;
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
for(int i = 1; i <= n; i++) {
if((a[i] + m) % 7 == 0) flg = 1;
}
if(flg) puts("Yes");
else puts("No");
}
return 0;
}