当前位置:   article > 正文

Educational Codeforces Round 104 (Rated for Div. 2)补题

educational codeforces round 104 (rated for div. 2) e. cheap dinner

真菜,哎!!!

B题

我服了,早上一看就一眼看出来了。

cout<<k<<endl;
  • 1

我写成了 c o u t < < x < < e n d l ; cout<<x<<endl; cout<<x<<endl;
我服了

  • 题目链接
    Here
  • 思路
    找规律
  • 代码
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N=1e2+10;

#define x first 
#define y second 
#define PII pair<int,int>
int a[N];
int b[N];
void solve()
{
	ll n,k;
    cin>>n>>k;
    if(n%2==0){
        k%=n;
        if(k==0) k=n;
        cout<<k<<endl;
    }
    else{
        ll m=(n-1)/2;
        ll t=m*n;
        //cout<<"t:"<<t<<endl;
        k%=t;
        if(k==0) {
            cout<<n-1<<endl;
            return;
        }
        //cout<<"k:"<<k<<endl;
        if(k<=(n-1)){
            if(k<=m) cout<<k<<endl;
            else cout<<k+1<<endl;
        }
        else{
            //cout<<"k:"<<k<<endl;
            k-=(n-1);
            //cout<<"k:"<<k<<endl;
            ll x=k/(n-2);
            //cout<<"x:"<<x<<endl;
            if(k%(n-2)!=0) x++;
            //cout<<"x:"<<x<<endl;
            k%=(n-2);
            if(k==0) k=n-2;
            //cout<<"k:"<<k<<endl;
            if(k<x) cout<<k<<endl;
            else if(k>=x&&k<((n+1)/2+x-1)) cout<<k+1<<endl;
            else cout<<k+2<<endl;
        }
    }
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
    {
		solve();
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64

A题

这个比较简单就不说了。

D题

  • 题意
    正常的应该是   a 2 + b 2 = c 2   ~a^2+b^2=c^2~  a2+b2=c2 ,但是出题人 c = a 2 − b c=a^2-b c=a2b 认为这个公式是正确的。问给你一个n,有几组勾股数满足上述关系。
  • 思路
    找规律,然后打表,二分查找
  • 代码
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N=1e5+10;

#define x first 
#define y second 
#define PII pair<int,int>
ll a[N];

void solve()
{
	int n;
    cin>>n;
	if(n<5){
		cout<<0<<endl;return;
	}
	int p=lower_bound(a+1,a+2+int(sqrt(n)),n)-a;
	if(a[p]==n) cout<<p<<endl;//这块要注意。
	else
	cout<<p-1<<endl;
}
int main()
{
	for(int i=1;i<=N;i++)
	{
		a[i]=5+8*(i-1)+(i-1)*(i-2)*2;
	}
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
    {
		solve();
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

大部分人的做法

void solve()
{
    int n;cin>>n;
    int ans=0;
    for(int i=1;i*i<=2*n-1;i+=2)
    {
        int a=i;
        int b=(a*a-1)/2,c=(a*a+1)/2;
        if(a<=b && b<=c && c<=n)
        {
            ans++;
        }
    }
    cout<<ans<<nl;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

C题

  • 题意
    给你n个球队,问你能够否构造一种比赛结果,使得最后所有球队的分数相同,而且平局数最少。
  • 思路
    如果是奇数,那就 1   − 1   1   − 1 1~-1~1~-1 1 1 1 1填充;
    如果是偶数,那就有一个平局,剩下的按照奇数样式填充;
  • 代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int ntest;
	cin >> ntest;
	for (int test = 0; test < ntest; test++)
	{
		int n;
		cin >> n;
		int a[n + 10][n + 10];
		memset(a, 0, sizeof(a));
		if (n == 2)
		{
			cout << 0 << endl;
			continue;
		}
		if (n % 2 == 1)
		{
			for (int i = 1; i < n; i++)
				for (int j = i + 1; j <= n; j++)
				{
					if ((i + j) % 2 == 1) cout << 1 << " ";
					else cout << -1 << " ";
				}
			cout << endl;
		}
		else
		{
			for (int i = 1; i < n; i++)
				for (int j = i + 1; j <= n; j++)
				{
					if (i % 2 == 1 && j == i + 1) cout << 0 << " ";
					else
					{
						if ((i + j) % 2 == 1) cout << 1 << " ";
						else cout << -1 << " ";
					}
				}
			cout << endl;
		}
	}
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/55103
推荐阅读
相关标签
  

闽ICP备14008679号