比赛连接
打着打着吃饭去了,又掉分了!
A. Goals of Victory
题意:
一场比赛有n个球队,每一个队伍匹配一次,球队的效率等于球队的得分数减去对手的得分数,给出n-1个数据,让你求出未给出的那个数据。
思路:
所有球队的效率和为0
代码:
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin>>n;
int ans=0;
for(int i=1;i<n;i++){
int x;
cin>>x;
ans+=x;
}
cout<<-1*ans<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
B. Helmets in Night Light
题意:
村长要将一条消息通知到全村,村长通知一个人的花费是p元,第i个人可通知ai个人,通知一人花费bi元,问要想全村人知道,最少的花费是多少。
思路:
看题意就知道是一个比较简单模拟,我们只需要按照通知一人花费的费用进行排序,从前往后统计一下人数就行,只要够了n个人直接退出循环。注意数据大小就行,我一开始就是没有注意数据大小提交错了一次。
代码:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
int t;
int n,p;
pair<int,int> a[N];
int main() {
scanf("%d",&t);
while(t--) {
scanf("%d%d",&n,&p);
for(int i=1;i<=n;i++) {
scanf("%d",&a[i].second);
}
for(int i=1;i<=n;i++) {
scanf("%d",&a[i].first);
}
a[n+1]={p,n};
sort(a+1,a+1+n+1);
int cnt=1;
ll ans=p;
for(int i=1;i<=n+1;i++) {
a[i].second=min(a[i].second,n-cnt);
cnt+=a[i].second;
ans+=1ll*a[i].first*a[i].second;
if(cnt==n) break;
}
printf("%lld\n",ans);
}
return 0;
}
C. Joyboard
题意:
给三个变量 n,m,k;构造一个长度为n+1的数组,满足
\[ai=a(i+1) mod i
\]
同时满足数组中的元素不能大于m,数组中不同种类的数字个数满足k个
思路:
找规律问题,多写几个样例,或者是打个表就会发现。
k>3时候没有结果,k最多取1,2,3
之后我们对n和m之间的关系进行比较
m< n时候当a(n+1)=0时候k=1,当a(n+1)=0~m时候,k=2
m>=n时候
当a(n+1)=0 k=1
a(n+1)=1~n or a(n+1)=kn (kn<=m) k=2 一共有n-1+m/n种方法
k=3 m+1-ans ans是当k=1 or 2时候方法的总和
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
ll n, m, k; cin >> n >> m >> k;
if (k > 3) {cout << 0 << endl;return ;}
int ans;
if (m < n) {
if (k == 1)ans = 1;
if (k == 2)ans = m;
if (k == 3)ans = 0;
}
else {
if (k == 1) { ans = 1; }
if (k == 2) {
if (m >= k)ans = n + m / n - 1;
else ans = m;
}
if (k == 3) {
ans = m + 1;
ll ans1 = 1;
ll ans2 = n - 1 + m / n;
ans -= ans1 + ans2;
}
}
cout << ans << endl;
}
int main(){
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
- Round Codeforces COMPFEST Final basedround codeforces compfest final codeforces compfest round final round codeforces rated based venture final round 2016 educational codeforces round rated codeforces round 911 div codeforces round 864 div codeforces round 887 div codeforces round 863 div codeforces round 913 div