Codeforces Round 909 (Div. 3)
A
#include <bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;
int n;
void solve(){
cin>>n;
for(int i=1;i<=10;i++){
if(i&1){
if(n%3==0) n++;
else{
cout<<"First"<<endl;
return;
}
}else{
if(n%3==1) n--;
else if(n%3==2) n++;
else n--;
}
}
cout<<"Second"<<endl;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
B
没想到是这么脑残的暴力,,,写半天。
#include <bits/stdc++.h>
#define int unsigned long long
#define endl '\n';
using namespace std;
const int N = 2e5 + 10;
int n;
unsigned long long pre[N];
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>pre[i];
pre[i]+=pre[i-1];
}
int ans=0;
for(int len=1;len<=n/2;len++){
if(n%len) continue;
int sum1=0;
int sum2=0;
for(int i=len;i<=n;i+=len){
if(sum1==0) sum1=pre[i]-pre[i-len];
if(sum2==0) sum2=pre[i]-pre[i-len];
sum1=max(sum1,pre[i]-pre[i-len]);
sum2=min(sum2,pre[i]-pre[i-len]);
}
ans=max(ans,sum1-sum2);
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
C
很典的贪心。代码写的很丑,写晕了。
#include <bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;
const int N = 2e5 + 10;
int a[N];
int n;
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int ans=a[1];
int sum=max(0ll,a[1]);
for(int i=2;i<=n;i++){
if((a[i]&1)^(a[i-1]&1)){
sum+=a[i];
ans=max(ans,sum);
ans=max(ans,a[i]);
if(sum<=0) sum=0;
}else{
if(a[i]>0){
sum=a[i];
ans=max(sum,ans);
}
else{
sum=0;
ans=max(ans,a[i]);
}
}
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
D
如果 2的a[i]次方/a[i]2的a[j]次方/a[j] 的话{i,j}就是符合题意的,两边都取对数就是 a[i]-log2(a[i])a[j]-log2(a[j])
(这种用了log2的代码不知道会不会被卡掉)
#include <bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;
const int N = 2e5 + 10;
int a[N];
long double b[N];
int n;
void solve(){
map<long double,int> path;
int ans=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
long double x;
x=1.0*a[i]-log2(a[i]);
ans+=path[x];
path[x]++;
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
E
可以发现如果出现 a[i]<a[i-1] ,那么i之前的所有数都要进行一次操作。所以找最后一个逆序出现的位置就行了。
#include <bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;
const int N = 2e5 + 10;
int a[N];
int n;
void solve(){
cin>>n;
deque<int> path;
int minn=-1;
for(int i=1;i<=n;i++){
cin>>a[i];
if(minn==-1) minn=a[i];
minn=min(a[i],minn);
if(a[i]<a[i-1]) path.push_back(i);
}
if(path.empty()){
cout<<0<<endl;
return;
}
int ans=path.back()-1;
for(int i=1;i<=ans;i++)
if(a[i]==minn){
cout<<-1<<endl;
return;
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
F
写的时候一直没理解题目,,,其实好像拿一个点出来来回跑就行了,
感觉今天这场的题意都怪怪的
看了下别人的代码好像都是维护两条链的.
大佬代码:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
void solve() {
int n, q;cin >> n >> q;
vector<int> list1,list2;
for(int i=2;i<=n;i++){
cout<<i-1<<" "<<i<<"\n";
list1.push_back(i);
}
list2.push_back(2);
for(int i=1;i<=q;i++){
int x;cin>>x;
if(list1.size()==x){
cout<<"-1 -1 -1\n";
continue;
}
if(list1.size()>x){
vector<int> st;
while(list1.size()>x){
st.push_back(list1.back());
list1.pop_back();
}
cout<<st.back()<<" "<<list1.back()<<" "<<list2.back()<<"\n";
while(!st.empty()){
list2.push_back(st.back());
st.pop_back();
}
}else{
vector<int> st;
while(list1.size()+st.size()<x){
st.push_back(list2.back());
list2.pop_back();
}
cout<<st.back()<<" "<<list2.back()<<" "<<list1.back()<<"\n";
while(!st.empty()){
list1.push_back(st.back());
st.pop_back();
}
}
}
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);
int t;cin >> t;
while (t--) solve();
return 0;
}
标签:int,909,Codeforces,long,while,solve,ans,Div,define
From: https://www.cnblogs.com/zfxyyy/p/17875707.html