Nothing to fear
those times when you get up early and you work hard; those times when you stay up late and you work hard; those times when don’t feel like working — you’re too tired, you don’t want to push yourself — but you do it anyway. That is actually the dream. That’s the dream. It’s not the destination, it’s the journey. And if you guys can understand that, what you’ll see happen is that you won’t accomplish your dreams, your dreams won’t come true, something greater will. mamba out
那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~
2020.4.11
A
简单模拟 一发过
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std;
const int N = 30;
struct student{
int sc;
char t;
int sum;
student(){}
student(int sc, char ch):sc(sc), t(ch){}
};
int n , k;
int team[N][N];
int score[N]; // 记录每个队伍得平均值
vector<student> s;
// 计算每个队伍得平均值
void calavg(int x)
{
double tmp = 0 , sum = 0;
for(int i = 1;i <= k ;i ++)
{
tmp += team[i][x];
}
tmp = tmp / k;
int cnt = 0; //计数
for(int i = 1;i <= k ;i ++)
{
if(abs(tmp - team[i][x]) <= 15)
{
sum += team[i][x];
cnt++;
}
}
sum = sum / cnt;
score[x] = int(round(sum));
}
void init()
{
cin >> n >> k;
int sc , t;
for(int i = 1;i <= n ;i ++)
{
scanf("%d %c",&sc , &t);
s.push_back(student(sc,t));
}
for(int i = 1;i <= k; i++)
{
for(int j = 1;j <= k ;j ++)
{
scanf("%d",&team[i][j]);
}
}
// 初始化分数
for(int i = 1;i <= k ;i ++)
{
calavg(i);
}
}
bool cmp(student a, student b)
{
if(a.sum == b.sum)
{
return a.t < b.t;
}else return a.sum > b.sum;
}
int main()
{
init();
//计算学生的分数
for(int i = 0;i < (int)s.size(); i++)
{
s[i].sum = (int)round(s[i].sc * 0.6 + score[s[i].t - 'A' + 1] * 0.4);
}
sort(s.begin() ,s.end(),cmp);
for(int i = 0;i < (int)s.size(); i++)
{
printf("%d %c
",s[i].sum,s[i].t);
}
return 0;
}
B
贪心题 原题是leetcode 135分糖果 可恶啊 我想成二分答案转判定wa了
要进行正向和逆向两次贪心
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int N = 1000005;
int n , a[N];
ll f[N];
void init()
{
cin >> n;
for(int i = 1;i <= n ;i ++)
{
scanf("%d",&a[i]);
}
}
int main()
{
init();
ll sum = 0;
for(int i = 1;i <= n ;i ++)
{
if(a[i] > a[i-1]){
f[i] = f[i-1] + 1;
}else if(a[i] == a[i-1])
{
f[i] = f[i-1];
}else f[i] = 1;
}
for(int i = n ; i >= 1 ;i--)
{
if(a[i] > a[i+1]){
f[i] = max(f[i+1] + 1 , f[i]);
}else if(a[i] == a[i+1]){
f[i] = f[i+1];
}
}
for(int i = 1;i <= n ;i ++)
{
sum += f[i];
}
cout << sum << endl;
return 0;
}/*
7
1 2 4 3 3 5 6*/
C
STL的使用 我只想说下次读题别忘记把眼镜戴上QAQ 血亏了吧 明明能一发AC的
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int N = 1000005;
int n , f[N][3];
map<int,int> m;
void init()
{
cin >> n;
for(int i = 1;i <= n ;i ++)
{
scanf("%d %d",&f[i][0], &f[i][1]);
f[i][1] = f[i][0] ^ f[i][1];
int &a = f[i][0] , &b = f[i][1];
// 确保每一轮选择不一样的数字
m[a]++;m[b]++;
if(a == b)m[a]--;
}
}
int main()
{
init();
int ans = 0, cnt = 0;
for(auto it = m.begin(); it != m.end() ; it++)
{
int a = it->first , b = it->second;
if(b > cnt)
{
ans = a; cnt = b;
}
}
cout << ans << endl;
return 0;
}