头像

HH_moon

废物中的废物




离线:1天前


最近来访(59)
用户头像
玖玖
用户头像
DPH
用户头像
Botton
用户头像
edgdcgxgbx
用户头像
_Crush
用户头像
chiking
用户头像
RyanMoriarty
用户头像
Alexshwing
用户头像
用户头像
wuxie
用户头像
LHHHHHH
用户头像
Backlight
用户头像
MUN_Greenwood
用户头像
克里斯保罗
用户头像
signed
用户头像
悠.
用户头像
acm_yk
用户头像
unoff
用户头像
15358022392
用户头像
大鼻孔

活动打卡代码 AcWing 1843. 圆形牛棚

HH_moon
1天前
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+9;
const int INF=1e9;
int x[maxn];
int main(){
    int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>x[i];
        sum+=x[i];
    }
    int ans=INF;
    for(int i=1;i<=n;i++){
        int now=i;
        int cnt=sum-x[i];
        int step=0;
        int can=0;
        while(1){
            now++;
            step++;
            if(now>n)now=1;
            if(now==i)break;
            can+=cnt;
            cnt-=x[now];
        }
        ans=min(ans,can);
    }
    cout<<ans<<endl;
}


活动打卡代码 AcWing 1855. 愤怒的奶牛

HH_moon
1天前
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+9;
int x[maxn];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i];
    }
    sort(x+1,x+1+n);
    int ans=0;
    for(int i=1;i<=n;i++){
       // cout<<x[i]<<" ";
        int l=i;int r=i;
        int len=1;
        int lflag=1;int rflag=1;
        int lastl=i;int lastr=i;
        while(l>1||r<n){
            if(l==1||abs(x[l-1]-x[lastl])>len)lflag=0;
            if(r==n||abs(x[r+1]-x[lastr])>len)rflag=0;
            while(l>1&&lflag&&abs(x[l-1]-x[lastl])<=len)l--;
            while(r<n&&rflag&&abs(x[r+1]-x[lastr])<=len)r++;
            len++;
            if(!lflag&&!rflag)break;
            lastl=l;
            lastr=r;
        }
        ans=max(ans,r-l+1);
        //cout<<l<<" "<<r<<endl;
    }
    //cout<<endl;
    cout<<ans<<endl;
}


活动打卡代码 AcWing 1875. 贝茜的报复

HH_moon
3天前
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>p[8];
    for(int i=1;i<=n;i++){
        char c;int x;
        cin>>c>>x;
        if(c=='B')p[0].push_back(x);
        if(c=='E')p[1].push_back(x);
        if(c=='S')p[2].push_back(x);
        if(c=='I')p[3].push_back(x);
        if(c=='G')p[4].push_back(x);
        if(c=='O')p[5].push_back(x);
        if(c=='M')p[6].push_back(x);
    }
    int ans1=0;
    int siz[8]={0};
    for(int i=0;i<=6;i++)siz[i]=p[i].size();
    int sizz=siz[1]*siz[2]*siz[4]*siz[5]*siz[6];
    int now1=0;
    for(auto i:p[0]){
        for(auto j:p[3]){
            if((i+j)%2==0)ans1+=sizz,now1++;
        }
    }
    sizz=siz[0]*siz[3]*siz[6];
    int now2=0;
    for(auto g:p[4]){
        for(auto o:p[5]){
            for(auto e:p[1]){
                for(auto s:p[2]){
                    if((g+o+e+s)%2==0)ans1+=sizz,now2++;
                }
            }
        }
    }
    sizz=siz[0]*siz[1]*siz[2]*siz[3]*siz[4]*siz[5];
    int now3=0;
    for(auto m:p[6])if(m%2==0)ans1+=sizz,now3++;
    int ans2=now1*now2*siz[6];
    ans2+=now1*now3*(siz[2]*siz[1]*siz[4]*siz[5]);
    ans2+=now2*now3*(siz[0]*siz[3]);
    int ans3=0;
    ans3=now1*now2*now3;
    cout<<ans1-ans2+ans3<<endl;
}


活动打卡代码 AcWing 1884. COW

HH_moon
5天前
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    ll c=0;
    ll co=0;
    ll cow=0;
    for(auto i:s){
        if(i=='C')c++;
        if(i=='O')co+=c;
        if(i=='W')cow+=co;
    }
    cout<<cow<<endl;
}


活动打卡代码 AcWing 1904. 奶牛慢跑

HH_moon
6天前
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+9;
struct node{
    int x,v;
}x[maxn];
int s[maxn];
bool cmp(node a,node b){
    return a.x<b.x;
}
int find(int x){
 return s[x]==x?s[x]:s[x]=find(s[x]);   
}
void onion(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return ;
    s[x]=y;
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i].x>>x[i].v;
        s[i]=i;
    }
    sort(x+1,x+1+n,cmp);
    for(int i=n-1;i>=1;i--){
        if(x[i].v>x[find(i+1)].v){
            onion(i,i+1);
        }
    }
    vector<int>vec;
    for(int i=1;i<=n;i++){
        vec.push_back(find(i));
    }
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    cout<<vec.size()<<endl;
}


活动打卡代码 AcWing 1913. 公平摄影

HH_moon
7天前
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
signed main(){
    ll n;
    cin>>n;
    map<ll,ll>mp;
    vector<ll>vec;
    for(ll i=1;i<=n;i++){
        ll x;char b;
        cin>>x>>b;
        if(b=='G')mp[x]--;
        else mp[x]++;
        vec.push_back(x);
    }
    sort(vec.begin(),vec.end());
    map<ll,ll>vis;
    ll ans=0;
    ll now=0;
    vis[0]=vec[0];
    ll last1=0;
    ll last2=0;
    for(ll i=0;i<vec.size();i++){
        //cout<<vec[i]<<" ";
        now+=mp[vec[i]];
        if(vis[now]){
            ans=max(ans,vec[i]-vis[now]);
        }
        if(!vis[now]){
            vis[now]=vec[i+1];
            //cout<<now<<" "<<vis[now]<<" "<<vec[i]<<endl;
        }
        if(mp[vec[i]]==1&&last1){
            ans=max(ans,vec[i]-last1);
        }else if(mp[vec[i]]==-1&&last2){
            ans=max(ans,vec[i]-last2);
        }else if(mp[vec[i]]==1){
            last1=vec[i];
            last2=0;
        }else if(mp[vec[i]]==-1){
            last2=vec[i];
            last1=0;
        }
    }
    cout<<ans<<endl;
}


活动打卡代码 AcWing 1922. 懒惰的牛

HH_moon
8天前
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e6+9;
long long sum[maxn];
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        int g,x;
        cin>>g>>x;
        sum[max(0,x-k)]+=g;
        sum[x+k+1]-=g;
    }
    long long ans=0;
    for(int i=1;i<=maxn;i++){
        //cout<<sum[i]<<" ";
        sum[i]+=sum[i-1];
        ans=max(ans,sum[i]);
    }
    //cout<<endl;
    cout<<max(sum[0],ans)<<endl;
}


活动打卡代码 AcWing 1929. 镜子田地

HH_moon
9天前
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
int vis[1100][1100][4];
vector<char[1001]>mp(1001);
int n,m;
bool judge(int x,int y){
    if(x<0||y<0||x>n||y>m)return 0;
    return 1;
}
int dfs(int x,int y,int dir){
    if(vis[x][y][dir])return vis[x][y][dir];
    vis[x][y][dir]=1;
    int nx,ny;
    int ans=1;
    if(mp[x][y]=='/'){
        if(dir==0){
            nx=x-1;
            ny=y;
            if(judge(nx,ny))
                vis[x][y][dir]+=dfs(nx,ny,3);
        }else if(dir==1){
            nx=x;
            ny=y-1;
            if(judge(nx,ny))
                vis[x][y][dir]+=dfs(nx,ny,2);
        }else if(dir==2){
            nx=x+1;
            ny=y;
            if(judge(nx,ny))
                vis[x][y][dir]+=dfs(nx,ny,1);
        }else{
            nx=x;
            ny=y+1;
            if(judge(nx,ny))
                vis[x][y][dir]+=dfs(nx,ny,0);
        }
    }else{
        if(dir==0){
            nx=x+1;
            ny=y;
            if(judge(nx,ny))
                vis[x][y][dir]+=dfs(nx,ny,1);
        }else if(dir==1){
            nx=x;
            ny=y+1;
            if(judge(nx,ny))
                vis[x][y][dir]+=dfs(nx,ny,0);
        }else if(dir==2){
            nx=x-1;
            ny=y;
            if(judge(nx,ny))
                vis[x][y][dir]+=dfs(nx,ny,3);
        }else{
            nx=x;
            ny=y-1;
            if(judge(nx,ny))
                vis[x][y][dir]+=dfs(nx,ny,2);
        }
    }
    return vis[x][y][dir];
}
int main(){
    cin>>n>>m;
    n--;
    m--;
    for(int i=0;i<=n;i++){
        cin>>mp[i];
    }
    int ans=0;
    for(int i=0;i<=n;i++){
        ans=max(ans,dfs(i,0,0));
        ans=max(ans,dfs(i,m,2));
    }
    for(int i=0;i<=m;i++){
        ans=max(ans,dfs(0,i,1));
        ans=max(ans,dfs(n,i,3));
    }
    cout<<ans<<endl;
}


活动打卡代码 AcWing 1934. 贝茜放慢脚步

HH_moon
9天前
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    double ans=0;
    double nowdis=0;
    double nowv=1;
    double nowdi=1;
    vector<int>v1;
    vector<int>v2;
    for(int i=1;i<=n;i++){
        char c;int x;
        cin>>c>>x;
        if(c=='T'){
            v1.push_back(x);
        }else{
            v2.push_back(x);
        }
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    int i=0;int j=0;
    double times=0;
    while(i<v1.size()||j<v2.size()){
        if(i<v1.size()&&j<v2.size()){
            if(nowdis+(v1[i]-times)*nowv<=v2[j]){
                nowdis+=(v1[i]-times)*nowv;
                times=v1[i];
                nowdi+=1.0;
                nowv=1.0/nowdi;
                i++;
            }else{
                times+=(v2[j]-nowdis)/nowv;
                nowdis=v2[j];
                nowdi+=1.0;
                nowv=1.0/nowdi;
                j++;
            }
        }else if(i<v1.size()){
            nowdis+=(v1[i]-times)*nowv;
            times=v1[i];
            nowdi+=1.0;
            nowv=1.0/nowdi;
            i++;
        }else if(j<v2.size()){
            times+=(v2[j]-nowdis)/nowv;
            nowdis=v2[j];
            nowdi++;
            nowv=1.0/nowdi;
            j++;
        }
        //cout<<nowdis<<endl;
    }
    times+=(1000.0-nowdis)/nowv;
    if(times-floor(times)*1.0>=0.5){
        int ans=ceil(times);
        cout<<ans<<endl;
    }else {
        int ans=floor(times);
        cout<<ans<<endl;
    }
}


活动打卡代码 AcWing 1945. 奶牛棒球

HH_moon
9天前
#include<bits/stdc++.h>
using namespace std;
int a[1100];
vector<int>vec[1100];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    map<int,int>mp;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            vec[i].push_back(a[j]-a[i]);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int dis=a[j]-a[i];
            int pos1=lower_bound(vec[j].begin(),vec[j].end(),dis)-vec[j].begin();
            int pos2=upper_bound(vec[j].begin(),vec[j].end(),2*dis)-vec[j].begin()-1;
            ans+=max(0,pos2-pos1+1);
        }
    }
    cout<<ans<<endl;
}