Summer training #11

A:水

#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define EPS 1.0e-8
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; //min
typedef long long ll;
typedef unsigned long long ull;
bool cmplow(int a,int b)
{
 return a<b;
}
int num[10];
int main()
{
 freopen("bulls.in", "r", stdin);
 freopen("bulls.out", "w", stdout);
 mem(num,0);
  string a,b;
  cin >> a >> b;
  int n=0,m=0;
  for(int i=0;i<4;i++)
  {
        num[a[i]-'0']++;
  }
  for(int i=0;i<4;i++)
  {
        if(a[i]==b[i])
        {
        n++;
        }
        else
        {
        if(num[b[i]-'0']!=0)
        m++;
        }
  }
  cout<< n <<" "<< m;
}
View Code

B:要先搜 再记录路径 因为可走不代表是可行解 要后面门全部走完才能记录

include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define EPS 1.0e-8
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define pai pair<int,int>
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; //min
typedef long long ll;
typedef unsigned long long ull;
struct way
{
 int to;
 int val;
}w[4005];
int ans[4005];
int pop=1;
void dfs(int x)
{
 for(int gate=4*x-3;gate<=4*x;gate++)
 {
   if(w[gate].val==1)
   {
        w[w[gate].to].val=0;
        w[gate].val=0;
        dfs((w[gate].to+3)/4);
        ans[pop++]=w[gate].to;
        ans[pop++]=gate;
   }
 }
}
int main()
{
 freopen("courier.in", "r", stdin);
 freopen("courier.out", "w", stdout);
 mem(ans,0);
 mem(w,0);
 int n;
 cin >> n;
 for(int i=1;i<=2*n;i++)
 {
        int now,next;
        scanf("%d %d",&now,&next);
        w[now].to=next;
        w[next].to=now;
        w[now].val=w[next].val=1;
 }
 dfs(1);
 for(int i=1;i<=4*n;i++)
 {
        if(w[i].val==1)
        {
        cout<<"No"<<endl;
        return 0;
        }
 }
 cout<<"Yes"<<endl;
 cout<<ans[1];
 for(int i=2;i<=4*n;i++)
 {
        cout<<" "<<ans[i];
 }
}
View Code

C:没遇到一个转折点就往前和往后推

#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define EPS 1.0e-8
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; //min
typedef long long ll;
typedef unsigned long long ull;
int a[1000005];
int ans[100005];
int pop=1;
int main()
{
 freopen("dales.in", "r", stdin);
 freopen("dales.out", "w", stdout);
 int t;
 cin>> t;
 while(t--)
 {
        int n;
        cin >> n;
        for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
        int h=0,d=0;
        for(int i=2;i<n;i++)
        {
        if(a[i]>a[i-1]&&a[i]>a[i+1])
        {
        int now1,now2;
        for(now1=i-1;now1>0;now1--)
        {
        if(a[now1]>=a[now1+1])
        break;
        }
        for(now2=i+1;now2<=n;now2++)
        {
        if(a[now2]>=a[now2-1])
        break;
        }
        h=max(h,min(now2-i-1,i-now1-1));
        }
        else if(a[i]<a[i-1]&&a[i]<a[i+1])
        {
        int now1,now2;
        for(now1=i-1;now1>0;now1--)
        {
        if(a[now1]<=a[now1+1])
        break;
        }
        for(now2=i+1;now2<=n;now2++)
        {
        if(a[now2]<=a[now2-1])
        break;
        }
        d=max(d,min(now2-i-1,i-now1-1));
        }
        }
        cout<<h<<" "<<d<<endl;
 }
}
View Code

D:暴力打表找规律

1->2->4->10->32->122->544->2770->15872->101042->707584->5405530......要算ans[x] i从1开始到x-2 add=ans[i]*ans[x-1-i]/2*C(x-1,i) if(i!=1&&(x-i-i)!=1) add/=2 ans+=add;

#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define EPS 1.0e-8
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define pai pair<int,int>
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);

using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; //min
typedef long long ll;
typedef unsigned long long ull;
struct way
{
 int to;
 int val;
}w[4005];
int ans[4005];
int pop=1;
void dfs(int x)
{
 for(int gate=4*x;gate>=4*x-3;gate--)
 {
   if(w[gate].val==1)
   {
        w[w[gate].to].val=0;
        w[gate].val=0;
        dfs((w[gate].to+3)/4);
        ans[pop++]=w[gate].to;
        ans[pop++]=gate;
   }
 }
}
int main()
{
 freopen("courier.in", "r", stdin);
 freopen("courier.out", "w", stdout);
 mem(ans,0);
 mem(w,0);
 int n;
 cin >> n;
 for(int i=1;i<=2*n;i++)
 {
        int now,next;
        scanf("%d %d",&now,&next);
        w[now].to=next;
        w[next].to=now;
        w[now].val=w[next].val=1;
 }
 dfs(1);
 for(int i=1;i<=4*n;i++)
 {
        if(w[i].val==1)
        {
        cout<<"No"<<endl;
        return 0;
        }
 }
 cout<<"Yes"<<endl;
 cout<<ans[1];
 for(int i=2;i<=4*n;i++)
 {
        cout<<" "<<ans[i];
 }
}
View Code

F:打表约数 枚举

G:数位DP

posted @ 2017-07-20 11:45  Aragaki  阅读(116)  评论(0编辑  收藏  举报