真菜,哎!!!
B题
我服了,早上一看就一眼看出来了。
cout<<k<<endl;
我写成了
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();
}
}
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=a2−b 认为这个公式是正确的。问给你一个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();
}
}
大部分人的做法
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;
}
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;
}