2021-02-18 Educational Codeforces Round 104

A. Arena

弱弱果然只会第一道。
题干说到相同的对手可以不断地比,因此只要和最差的人比,谁都可能是赢家,所以可能赢的人数即是总人数减去水平最差的人数

#include<bits/stdc++.h>
using namespace std;
int t, n, a[102];
bool cmp(int a, int b){
	return a>b;
}
int main(){
	cin >> t;
	while(t--){
		int i;
		cin >> n;
		for(i=0; i<n; ++i){
			cin >> a[i];
		}
		sort(a, a+n, cmp);
		for(i=n-1; i>=1; --i){
			if(a[i] != a[i-1]){
				break;
			}
		}
		cout << i << endl;
	}
} 

B. Cat Cycle

比赛的时候没有想到n为偶数时两只猫是不会产生相遇的,还是自己太弱。
n为偶数时,两只猫不会相遇,因为B猫的初始地点为1,且第一个小时猫是不会动的,所以(k-1)%n+1

n为奇数时,两只猫会有相遇,把相遇多出来的步数加上即可,两种情况1.A从n开始,B从1开始。2.第一次相遇后A从x开始,B从x+1开始。两种情况再次相遇所需的时间相同
时间为(n-1)/2,多走的步数为(k-1)/((n-1)/2))%n+1;

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t, n, k;
ll a, b;
int main(){
	cin >> t;
	while(t--){
		cin >> n >> k;
		if(n%2 == 0) cout << (k-1)%n+1 << endl;
		else cout << (k-1+(k-1)/((n-1)/2))%n+1 <<endl;
	}
}

C. Minimum Ties

分奇偶讨论
奇数:每人比赛n-1场,赢输各(n-1)/2即可
1,-1,1,-1,1,-1…即可
偶数:平一局,赢输各(n-2)/2
比如4人:0 1 -1 | -1 1 | 0

#include<bits/stdc++.h>
using namespace std;
int t, n;
int main() {
	cin >> t;
	while(t--){
		cin >> n;
		if (n%2 == 1){
			long long a = (n-1)/2 * n;
			for(int i=1; i<=a; ++i){
				if(i%2 == 1) cout << "1" << ' ';
				else cout << "-1" << ' ';
			}
		}
		else {
			for(int i=1; i<=n-1; ++i){
				if (i%2 == 1){
					cout << "0" << ' ';
					for(int j=1; j<=n-i-1; ++j)
					    if(j%2 == 1) cout << "1" << ' ';
					    else cout << "-1" << ' ';
				}
				else {
					for(int j=1; j<=n-i; ++j)
					    if(j%2 == 1) cout << "-1" << ' ';
					    else cout << "1" << ' ';
				}
			}
		}
		cout << endl;
    }
}

D. Pythagorean Triples

c= a 2 a^2 a2-b
c 2 c^2 c2= b 2 b^2 b2+ a 2 a^2 a2
消元 c=b+1;
代入 a 2 a^2 a2=2b+1
a=sqrt(2b+1);
a=sqrt(2c-1);
因为c小于等于n,求出小于等于2n-1的完全平方数的个数即可
a=1不行,去掉1个
c=( a 2 a^2 a2+1)/2
a,b,c都要为整数,a为奇数,总个数再除2

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t, n;
int main(){
	cin >> t;
	while(t--){
		cin >> n;
		ll a = (sqrt(2*n-1)+1)/2-1;
		cout << a << endl;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值