Codeforces 902 树同型构造 多项式长除法构造(辗转相除法)

 A

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double eps = 1.0e-6;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + 10;
const int  maxm = 300;
const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
//next_permutation
ll mod = 1e9 + 7;
int n, aim;
int v[105];
int main()
{
        //freopen("in.txt", "r", stdin);
        //freopen("out1.txt", "w", stdout);
        cin >> n >> aim;
        int pa = 0, pb = 0;
        v[0] = 1;
        for (int i = 1; i <= n; i++)
        {
                cin >> pa >> pb;
                if (!v[pa])
                {
                        cout << "NO" << endl;
                        exit(0);
                }
                for (int j = pa; j <= pb; j++)
                {
                        //cout<<j<<endl;
                        v[j] = 1;
                }
                if (v[aim])
                {
                        cout << "YES" << endl;
                        exit(0);
                }
        }
        cout << "NO" << endl;
}
View Code

 B

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 0x3f3f3f3f
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int n;
vector<int> tree[10005];
int anser = 0;
int color[10005];
int aim[10005];
void dfs(int x, int now)
{
        if (now != aim[x])
        {
                anser++;
                now = aim[x];
        }
        int len = tree[x].size();
        for (int i = 0; i < len; i++)
        {
                int to = tree[x][i];
                dfs(to, now);
        }
}
int main()
{
        //freopen("out.txt","w",stdout);
        cin >> n;
        for (int i = 2; i <= n; i++)
        {
                int now;
                cin >> now;
                tree[now].pb(i);
        }
        for (int i = 1; i <= n; i++)
        {
                cin >> aim[i];
        }
        dfs(1, 0);
        cout << anser << endl;
        return 0;
}
View Code

 C

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double eps = 1.0e-6;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + 10;
const int  maxm = 300;
const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
//next_permutation
ll mod = 1e9 + 7;
int n;
int h[100085];
int main()
{
        //freopen("in.txt", "r", stdin);
        //freopen("out1.txt", "w", stdout);
        cin >> n;
        int flag = 0;
        int now = 0;
        for (int i = 1; i <= n + 1; i++)
        {
                scanf("%d", h + i);
                if (h[i - 1] > 1 && h[i] > 1)
                {
                        flag = 1;
                }
        }
        if (!flag)
        {
                cout << "perfect" << endl;
        }
        else
        {
                cout << "ambiguous" << endl;
                for (int i = 1; i <= n + 1; i++)
                {
                        for (int j = 1; j <= h[i]; j++)
                        {
                                cout << now << " ";
                        }
                        now += h[i];
                }
                cout << endl;
                int flag2 = 1;
                now = 0;
                for (int i = 1; i <= n + 1; i++)
                {
                        if (h[i - 1] > 1 && h[i] > 1 && flag2)
                        {
                                flag2 = 0;
                                cout << now - 1 <<" ";
                                for (int j = 1; j <= h[i] - 1; j++)
                                {
                                        cout << now << " ";
                                }
                        }
                        else
                        {
                                for (int j = 1; j <= h[i]; j++)
                                {
                                        cout << now << " ";
                                }
                        }
                        now += h[i];
                }
                cout << endl;
        }
}
View Code

 D

 要求你给出两个多项式 使得A,B辗转相除N次得到答案(B为0)

仿照斐波那契数列使得Fn=x*Fn-1±Fn-2  后面的±的作用是使得给出的多项式满足系数绝对值不超过1的条件

数组可以滚动

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 0x3f3f3f3f
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int anser[155][155];
int main()
{
        anser[0][0] = 1;
        anser[1][0] = 0;
        anser[1][1] = 1;
        int n;
        int aim = 1;
        cin >> n;
        for (int i = 2; i <= n; i++)
        {
                aim ^= 1;
                for (int j = 1; j <= i; j++)
                {
                        anser[aim][j] = (anser[aim][j] + anser[aim ^ 1][j - 1]) % 2;
                }
        }
        cout << n << endl;
        for (int i = 0; i <= n; i++)
        {
                cout << anser[aim][i] << " ";
        }
        cout << endl << n - 1 << endl;
        for (int i = 0; i < n; i++)
        {
                cout << anser[aim ^ 1][i] << " ";
        }
        cout << endl;
}
View Code

 

posted @ 2018-04-16 00:03  Aragaki  阅读(423)  评论(0编辑  收藏  举报