CodeForces 402

CodeForces 402A

水题,模拟

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const double g=10.0,eps=1e-7;
const int N=100000+10,maxn=500+100,inf=0x3f3f3f;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k,a,b,v;
    cin>>k>>a>>b>>v;
    int ans=0;
    while(a>0){
        if(b>0)
        {
            if(b>=k-1)
            {
                b-=k-1;
                a-=v*k;
            }
            else
            {
                a-=(b+1)*v;
                b=0;
            }
        }
        else
        {
            a-=v;
        }
      //  cout<<a<<endl;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}
/*********************

********************/
A

CodeForces 402B

wa了两发,因为没有注意必须为正的情况

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const double g=10.0,eps=1e-7;
const int N=1000+10,maxn=500+100,inf=0x3f3f3f;

int a[N],ans[N],b[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=1+i*k;
    }
    int res=n+2;
    for(int i=0;i<3000;i++)
    {
        int sum=0;
        for(int j=0;j<n;j++)
            if(b[j]+i!=a[j])
                sum++;
        if(sum<res)
        {
            res=sum;
            for(int j=0;j<n;j++)
                ans[j]=b[j]+i;
        }
    }
    cout<<res<<endl;
    for(int i=0;i<n;i++)
    {
        if(a[i]>ans[i])cout<<"- "<<i+1<<" "<<a[i]-ans[i]<<endl;
        else if(a[i]<ans[i])cout<<"+ "<<i+1<<" "<<ans[i]-a[i]<<endl;
    }
    return 0;
}
/*********************

********************/
B

CodeForces 402E

这题以为是找规律之类的,后来发现居然是个强连通。。。把坐标转化为点,值大于1代表联通,如果整个图构成了一个强联通就可以

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const double g=10.0,eps=1e-7;
const int N=2000+10,maxn=500+100,inf=0x3f3f3f;

int n;
stack<int>s;
vector<int>v[N],ans[N];
int dfn[N],low[N];
int ins[N],inans[N];
int num,index;
void trajan(int u)
{
    ins[u]=2;
    low[u]=dfn[u]=++index;
    s.push(u);
    for(int i=0;i<v[u].size();i++)
    {
        int t=v[u][i];
        if(dfn[t]==0)
        {
            trajan(t);
            low[u]=min(low[u],low[t]);
        }
        else if(ins[t]==2)low[u]=min(low[u],dfn[t]);
    }
    if(low[u]==dfn[u])
    {
        ++num;
        while(!s.empty()){
            int k=s.top();
            s.pop();
            ins[k]=1;
            ans[num].push_back(k);
            inans[k]=num;
            if(k==u)break;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            int m;
            cin>>m;
            if(i!=j&&m!=0)v[i].push_back(j);
        }
    memset(ins,0,sizeof ins);
    memset(inans,0,sizeof inans);
    memset(dfn,0,sizeof dfn);
    memset(low,0,sizeof low);
    num=index=0;
    for(int i=1;i<=n;i++)
        if(!dfn[i])
           trajan(i);
    if(num!=1)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}
/********************
10
1 0 1 1 0 1 1 1 0 1
0 1 0 0 1 0 0 0 1 0
1 0 1 1 0 1 1 1 0 1
1 0 1 1 0 1 1 1 0 1
0 1 0 0 1 0 0 0 1 0
1 0 1 1 0 1 1 1 0 1
1 0 1 1 0 1 1 1 0 1
1 0 1 1 0 1 1 1 0 1
0 1 0 0 1 0 0 0 1 0
1 0 1 1 0 1 1 1 0 1
********************/
View Code
原文地址:https://www.cnblogs.com/acjiumeng/p/7249633.html