赞
踩
真菜,哎!!!
我服了,早上一看就一眼看出来了。
cout<<k<<endl;
我写成了
c
o
u
t
<
<
x
<
<
e
n
d
l
;
cout<<x<<endl;
cout<<x<<endl;
我服了
#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(); } }
这个比较简单就不说了。
#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;
}
#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; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。