Simulation game 3

1.HDU: 5138

Attendance problems; directly subtract that number 5 on the list

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=1e6+10;
typedef long long ll;
int ans[maxn];
int b[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    int n;
    while(cin>>n){
        ans[1]=n-15;
        ans[2]=n-7;
        ans[3]=n-4;
        ans[4]=n-2;
        ans[5]=n-1;
        int tot=0;
        for(int i=1;i<=5;i++){
            if(ans[i]>0){
                b[tot++]=ans[i];
            }
        }
        for(int i=0;i<tot;i++){
            if(i==tot-1)cout<<b[i]<<endl;
            else cout<<b[i]<<' ';
        }
    }



    return 0;
}
View Code

2.HDU: 6075

Question is intended: to an array ai, the number of seek ai% m = k is greater than the remaining number;

Directly determine the number of parity;

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
int main(){
    ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        int cnt1=0,cnt2=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            if(a[i]%2)cnt1++;
            else cnt2++;
        }
        if(cnt1>cnt2){
            cout<<"2"<<' '<<"1"<<endl;
        }
        else cout<<"2"<<' '<<"0"<<endl;
    }



    return 0;
}
View Code

3.poj: 2967

Question is intended: to give you a stick n, it determines whether the condition: at least three sticks can be combined into a triangle, and there are three sticks can not form a triangle;

! ! ! ! This title card input, was not the board, it has been T;

Solution: sorting, then sweep over the recording can be combined into a triangle, and then use the minimum and maximum of two wooden sticks, recording whether the triangle is formed;

Use character fast read;

#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn=1e6+10;
typedef long long ll;
ll a[maxn];
inline int read(){
    ll x=0LL,f=1LL;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)a[i]=read();
    //for(int i=1;i<=n;i++)cout<<a[i]<<' ';cout<<endl;
    sort(a+1,a+1+n);
    int flag=0,cnt=0;
    for(int i=1;i<=n-2;i++){
        if((1LL*a[i]+1LL*a[i+1])>a[i+2])flag=1;
        else cnt=1;
    }
    if((1LL*a[1]+1LL*a[2])<=a[n])cnt=1;
    if((flag==0)||(cnt==0))printf("The set is rejected.\n");
    else printf("The set is accepted.\n");



    return 0;
}
View Code

4.CF-892D

Question is intended: to an array a, b construct an array, each string b satisfies the prefix of each location and a different and are;

! ! ! At that time reading the wrong meaning of the questions: thought it was only a prefix and different ...... crazy wa, also tm thought was right;

Solution: Save for a sorting C, and then look for each ai is greater than the first value is placed ai bi (prefix must ensure that each string and different), then encounters the maximum, minimum discharge;

#include <bits/stdc++.h>
using namespace std;
const int maxn=100;
int a[maxn];
int b[maxn];
int ans[maxn];
bool vis[maxn];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b+1,b+1+n);
    for(int i=1;i<=n;i++){
        int flag=0;
        for(int j=1;j<=n;j++){
            if(a[i]<b[j]&&!vis[j]){
                ans[i]=b[j];
                vis[j]=true;
                flag=1;
                break;
            }
        }
        if(flag==0){
            ans[i]=b[1];
            vis[1]=true;
        }
    }
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<' ';
    }
    cout<<endl;

    return 0;
}
View Code

5.HDU: 5687

Meaning of the title: the dictionary tree;

! ! ! I do not know what was wrong, and back to the dorm to call again. . . . . tm;

#include <bits/stdc++.h>
using namespace std;
struct node{
    node *next[30];
    int cnt;
    node(){
        for(int i=0;i<30;i++)next[i]=NULL;
        cnt=0;
    }
};
node *root=new node();
void add(string s){
    int len=s.size();
    node *p=root;
    for(int i=0;i<len;i++){
        int x=s[i]-'a';
        if(p->next[x]==NULL)p->next[x]=new node();
        p=p->next[x];
        p->cnt++;
    }
}
void gao(string s){
    node *p=root;
    int len=s.size();
    for(int i=0;i<len;i++){
        int x=s[i]-'a';
        if(p->next[x]==NULL){
            cout<<"No"<<endl;return;
        }
        p=p->next[x];
    }
    if(p->cnt>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
void alldel(node *p){
    if(p==NULL)return;
    for(int i=0;i<30;i++){
        if(p->next[i]==NULL)alldel(p->next[i]);
    }
    delete(p);
}
void del(string s){
    int len=s.size();
    node *p=root,*pre;
    for(int i=0;i<len;i++){
        int x=s[i]-'a';
        if(p->next[x]==NULL)return ;
        pre=p;
        p=p->next[x];
    }
    int num=p->cnt;
    alldel(p);
    pre->next[s[s.size()-1]-'a']=NULL;
    p=root;
    for(int i=0;i<len-1;i++){
        int x=s[i]-'a';
        p=p->next[x];
        p->cnt-=num;
    }
}
int main(){
    int n;
    cin>>n;
    while(n--){
        string s,q;
        cin>>q>>s;
        if(q[0]=='i')add(s);
        else if(q[0]=='s')gao(s);
        else del(s);

    }



    return 0;
}
View Code

6klaigtoj-1095

The meaning of problems: a number of 1-n, the number of combinations of k find the position of the same number of 1-m;

Wrong row: Why They know, I do not know. . . Chicken to weakly

Solution: C (m, k) m is selected from invariant k, mk mistake remaining rows, the number nm then there may be 0 Staggered, Staggered 1, 2, 3 ,. . . ;

So to enumerate all possible;

Staggered equation: Dn = (n-1) (Dn-1 + Dn-2);

#include <iostream>
using namespace std;
typedef long long ll;
const int maxn=1e4+10;
const int mod=1e9+7;
ll c[maxn];
ll inv[maxn],fac[maxn],ans[maxn],pos[maxn];
ll qpow(ll a,int b)
{
    ll ans=1;
    a%=mod;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return ans;
}
void pre()
{
    fac[0]=fac[1]=1;
    for(int i=2;i<maxn;++i) fac[i]=i*fac[i-1]%mod;
    inv[maxn-1]=qpow(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
ll Comb(int n,int k)//求C(n,k)
{
    if (k < 0 || k > n) return 0;
    return fac[n]*inv[k]%mod *inv[n-k]%mod;
}
void init(){
    c[0]=1;
    c[1]=0;
    c[2]=1;
    for(ll i=3;i<=1005;i++)
        c[i]=((i-1)*(c[i-1]+c[i-2]))%mod;
}
int main(){
    init();
    pre();
    int T;
    cin>>T;
    int flag=1;
    while(T--){
        int n,m,k;
        cin>>n>>m>>k;
        ll ans=0;
        for(int i=0;i<=n-m;i++){
            ans=(ans+(c[n-k-i]%mod*Comb(n-m,i)%mod)%mod)%mod;
        }
        ans=((ans%mod)*(Comb(m,k)%mod))%mod;
        cout<<"Case "<<flag++<<": ";
        cout<<ans<<endl;
    }



    return 0;
}
View Code

7.HDU: 2962

8.CF:763A

Guess you like

Origin www.cnblogs.com/lin1874/p/11426880.html