B - Best Relay Team
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-8
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e5 + 10;
const int M = 1111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;
struct node{
string s;
double x,y;
};
node dp[N];
node mp[N];
string ans[N];
bool cmp(node x,node y){
return x.y<y.y;
}
void solve(){
int n;
cin>>n;
double minn=INF;
for(int i=1;i<=n;i++){
cin>>dp[i].s>>dp[i].x>>dp[i].y;
}
for(int i=1;i<=n;i++){
int pos=0;
for(int j=1;j<=n;j++){
if(i==j) continue;
mp[pos++]=dp[j];
}
sort(mp,mp+pos,cmp);
double res=0;
for(int j=0;j<3;j++){
res+=mp[j].y;
}
res+=dp[i].x;
if(minn>res){
minn=res;
ans[1]=dp[i].s;
ans[2]=mp[0].s;
ans[3]=mp[1].s;
ans[4]=mp[2].s;
}
}
printf("%.2f\n",minn);
for(int i=1;i<=4;i++){
cout<<ans[i]<<endl;
}
}
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
solve();
return 0;
}
G - Galactic Collegiate Programming Contest
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-8
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e5 + 10;
const int M = 1111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;
struct node{
int id;
int sum;
int tim;
bool operator<(const node &a) const{
if(sum!=a.sum) return sum>a.sum;
if(tim!=a.tim) return tim<a.tim;
return id<a.id;
}
};
node dp[N];
set<node>st;
void init(int n){
for(int i=1;i<=n;i++){
dp[i].id=i;
dp[i].sum=0;
dp[i].tim=0;
}
}
bool cmp(node x,node y){
if(x.sum>y.sum) return 1;
if(x.sum==y.sum&&x.tim<y.tim) return 1;
return 0;
}
void solve(){
int n,m;
cin>>n>>m;
init(n);
while(m--){
int id;
int k;
cin>>id>>k;
if(id==1){
dp[1].sum++;
dp[1].tim+=k;
}
else{
if(cmp(dp[id],dp[1])){
st.erase(st.find(dp[id]));
}
dp[id].sum++;
dp[id].tim+=k;
st.insert(dp[id]);
}
set<node>::iterator it;
while(!st.empty()){
it=st.end();
it--;
if(cmp(*it,dp[1])) break;
st.erase(it);
}
cout<<st.size()+1<<endl;
}
}
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
solve();
return 0;
}
J - Judging Moose
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-8
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e5 + 10;
const int M = 1111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;
void solve(){
int l,r;
cin>>l>>r;
if(l==r){
if(!l) cout<<"Not a moose"<<endl;
else cout<<"Even "<<l+r<<endl;
}
else{
cout<<"Odd "<<2*max(l,r)<<endl;
}
}
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
solve();
return 0;
}