[USACO17JAN] Secret Cow Code S - 洛谷(非常好的一道题)
cpp
#include<iostream>
#include<string>
using namespace std;
#define ull unsigned long long
int main(){
string s;
ull n;
cin>>s>>n;
ull sum=s.size();
while(sum<n){
ull k=sum;
while(n>k)k*=2;
k/=2;
n-=k+1;
if(n==0)n=k;
}
cout<<s[n-1]<<endl;
}
Status - Codeforces Round 891 (Div. 3) - Codeforces
cpp
#include<iostream>
#include<string>
using namespace std;
void solve(){
string s;
cin>>s;
s='0'+s;
int p=s.size();
for(int i=s.size()-1;i>=0;i--){
if(s[i]>='5')s[i-1]++,p=i;
}
int i;
if(s[0]=='0')i=1;
else i=0;
for(;i<s.size();i++){
if(i>=p)cout<<'0';
else cout<<s[i];
}
cout<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
cpp
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
#include<queue>
using namespace std;
const int N=500005;
int a[N];
int k=1e9;
void solve(){
int n;
cin>>n;
int m=n*(n-1)/2;
for(int i=0;i<m;i++){
cin>>a[i];
}
sort(a,a+m);
for(int i=0;i<m;i+=--n){
cout<<a[i]<<' ';
}
cout<<1000000000<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
cpp
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int N=200005;
int a[N];
int k=1e9;
typedef pair<int,int>PII;
PII b[N];
void solve(){
int n;
cin>>n;
vector<int>q;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
int x;
cin>>x;
b[i].first=a[i]-x;
b[i].second=i;
}
sort(b+1,b+n+1);
int sum=0;
for(int i=n;i>=1;i--){
if(i==n||b[i].first==b[i+1].first){
q.push_back(b[i].second);
}
else break;
}
sort(q.begin(),q.end());
cout<<q.size()<<endl;
for(int i=0;i<q.size();i++){
cout<<q[i]<<' ';
}
cout<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
cpp
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
#define ll long long
const int N=200005;
ll a[N];
typedef pair<ll,ll>PII;
PII b[N];
void solve(){
ll n;
cin>>n;
long long sum1=0,sum2=0;
for(ll i=0;i<n;i++){
ll x;
cin>>x;
b[i].first=x;
b[i].second=i;
sum1+=x;
}
sort(b,b+n);
for(int i=0;i<n;i++){
a[b[i].second]=sum1-(n-i)*b[i].first+n-i+i*b[i].first-sum2+i;
sum1-=b[i].first;
sum2+=b[i].first;
}
for(ll i=0;i<n;i++){
cout<<a[i]<<' ';
}
cout<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}