csust-8.12组队训练- Gym - 101466

目录

 

A - Gaby And Addition

B - Maximum Tree

C - Planet Communcation

D - Double it

E - Text Editor

F - Polygon Triangles

G - Generative Model

H - Logo

I - Math Class

J - Jeronimo's List

K - Random Numbers


A - Gaby And Addition

 Gym - 101466A 

题目链接https://codeforces.com/gym/101466/problem/A

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define ll long long
const ll inf = 4e18 + 10;
const int mac = 1e7 + 10;
const int mod = 3e7;
int x[mac], y[mac], z[mac];
int vis[mac], trie[mac][11], tot = 1;
int sum[mac];
ll tt[30];
char s[mac];
void insert(ll x, int rt);
ll find1(ll x, int rt);
ll find2(ll x, int rt);
int main()
{
	IOS;
	int n;
	cin >> n;
	tt[0] = 1;
	for (int i = 1; i < 19; i++) tt[i] = tt[i - 1] * 10;
	ll mi = inf, mx = 0, x;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		if (i != 1) {
			mi = min(mi, find2(x, 0));
			mx = max(mx, find1(x, 0));
		}
		insert(x, 0);
	}
	cout << mi << " " << mx << endl;
	return 0;
}
void insert(ll x, int rt) {
	int arr[22];
	for (int i = 0; i < 19; i++) arr[i] = x % 10, x /= 10;
	for (int i = 18; i >= 0; i--) {
		int p = arr[i];
		if (!trie[rt][p]) {
			trie[rt][p] = ++tot;
		}
		rt = trie[rt][p];
	}
}
ll find1(ll x, int rt) {
	int arr[22], idx, maxx;
	ll sss = 0;
	for (int i = 0; i < 19; i++) arr[i] = x % 10, x /= 10;
	for (int i = 18; i >= 0; i--) {
		maxx = -1, idx = -1;
		//int p = arr[i];
		for (int j = 0; j < 10; j++) {
			if (trie[rt][j] && (arr[i] + j) % 10 > maxx)
				maxx = (arr[i] + j) % 10, idx = j;
		}
		sss += tt[i] * maxx;
		rt = trie[rt][idx];
	}
	return sss;
}
ll find2(ll x, int rt) {
	int arr[22], idx, maxx;
	ll sss = 0;
	for (int i = 0; i < 19; i++) arr[i] = x % 10, x /= 10;
	for (int i = 18; i >= 0; i--) {
		maxx = 1000, idx = -1;
		//int p = arr[i];
		for (int j = 0; j < 10; j++) {
			if (trie[rt][j] && (arr[i] + j) % 10 < maxx)
				maxx = (arr[i] + j) % 10, idx = j;
		}
		sss += tt[i] * maxx;
		rt = trie[rt][idx];
	}
	return sss;
}

B - Maximum Tree

 Gym - 101466B 

题目链接https://codeforces.com/gym/101466/problem/B

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define ll long long
const int inf = 4e8 + 10;
const int mac = 100 + 10;
const int mod = 1e9 + 7;
ll a[100], f[100];
bool cmp(ll x, ll y)
{
	return x > y;
}
int main()
{
	IOS;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n, cmp);
	f[0] = 1;
	ll ans = 1;
	for (int i = 1; i <= n; i++) {
		f[i] = f[i - 1] * a[i];
		ans += f[i];
	}
	cout << ans << endl;
	return 0;
}

C - Planet Communcation

 Gym - 101466C 

题目链接https://codeforces.com/gym/101466/problem/C

#include <bits/stdc++.h>
using namespace std;

struct Point{
    int x, y ,z;
    Point(){};
    Point(int a, int b ,int c){x = a;y = b;z = c;}
    bool operator == (Point &temp ){
    return x == temp.x && y == temp.y && z == temp.z;
    }
}p[5000 + 10];

//map<Point,int> mp;

int main(){
    int n;
    int tot = 0;
    scanf("%d",&n);
    int ex,ey,ez;
    scanf("%d %d %d",&ex,&ey,&ez);
    for(int i = 2;i <= n ;i ++){
        int x , y ,z;
        scanf("%d %d %d",&x,&y,&z);
        x -= ex ,y -= ey ,z -= ez;
        if(x < 0){
            x = -x;
            y = -y;
            z = -z;
        }else if(x == 0){
            if(y < 0){
                y = -y;
                z = -z;
            }
        }else if(y < 0){
            if(z < 0){
                z = -z;
            }
        }
        int gcd = __gcd(__gcd(abs(x),abs(y)),abs(z));
        x /= gcd,y/=gcd,z/=gcd;
        Point temp;
        temp.x = x , temp.y = y, temp.z = z;
        
        if(tot == 0){
        p[++tot] = (Point){x,y,z};
        }
        else{
            int flag = 0;
            for(int j = 1;j <= tot;j ++ ){
                if((Point){x,y,z} == p[j]) flag ++;
            }
            if(!flag)p[tot++] =(Point){x,y,z};
        }
    }
    printf("%d",tot);
}

D - Double it

 Gym - 101466D 

题目链接https://codeforces.com/gym/101466/problem/D

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define ll long long
const int inf = 4e8 + 10;
const int mac = 1e4 + 10;
const int mod = 1e9 + 7;
int a[mac];
int main()
{
	IOS;
	int n;
	cin >> n;
	int num=0;
	while (n){
		if ((n-1)&1) {
			n=(n-2)/2;
			a[++num]=2;
		} 
		else {
			n=(n-1)/2;
			a[++num]=1;
		}
	}
	for (int i=num; i>=1; i--){
		if (a[i]==1) cout<<'A';
		else cout<<'B';
	}
	return 0;
}

E - Text Editor

 Gym - 101466E 

题目链接https://codeforces.com/gym/101466/problem/E

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
string str1,str2;
const int N = 1000002;
int nexts[N];

void getNext(string T,int tlen)
{
    int j, k;
    j = 0; k = -1; nexts[0] = -1;
    while(j < tlen)
        if(k == -1 || T[j] == T[k])
            nexts[++j] = ++k;
        else
            k = nexts[k];

}
void preKmp(string x[],int m,int kmpNext[]){
    int i,j;
    j=kmpNext[0]=-1;
    i=0;
    while(i<m){
        while(-1!=j && x[i]!=x[j])j=kmpNext[j];
        if(x[++i]==x[++j])kmpNext[i]=kmpNext[j];
        else kmpNext[i]=j;
    }
}

int mynext[maxn];
int KMP_Count(string T,int tlen,string S,int slen)
{
    int ans = 0;
    int i, j = 0;

    if(slen == 1 && tlen == 1)
    {
        if(S[0] == T[0])
            return 1;
        else
            return 0;
    }
    getNext(T,tlen);
    for(i = 0; i < slen; i++)
    {
        while(j > 0 && S[i] != T[j])
            j = nexts[j];
        if(S[i] == T[j])
            j++;
        if(j == tlen)
        {
            ans++;
            j = nexts[j];
        }
    }
    return ans;
}

int main(int argc, char const *argv[])
{
    getline(cin,str1);
    getline(cin,str2);
    int len;scanf("%d",&len);
    int len1 = str1.size();
    int len2 = str2.size();
    int l = 0,r = len2;
    int x = 0;
    while(l < r){
        int mid = (l + r + 1) >> 1;
        if(KMP_Count(str2.substr(0,mid),mid,str1,len1) >= len){ 
            l = mid;
            x =max( mid,x);
           
        }
        else r = mid - 1;
    }
    if(x) cout << str2.substr(0,x) << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

F - Polygon Triangles

 Gym - 101466F 

题目链接https://codeforces.com/gym/101466/problem/F

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define ll long long
const int inf = 4e8 + 10;
const int mac = 100 + 10;
const int mod = 1e9 + 7;
int a, b, c;
int main()
{
	IOS;
	int n;
	cin >> n;
	int mark = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a >> b >> c;
		if (a + b <= c || a + c <= b || b + c <= a) mark = 1;
	}
	if (mark) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

G - Generative Model

 Gym - 101466G 

题目链接https://codeforces.com/gym/101466/problem/G

 Gym - 101466H 

题目链接https://codeforces.com/gym/101466/problem/H

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define ll long long
const int inf = 4e8 + 10;
const int mac = 100 + 10;
const int mod = 1e9 + 7;
ll a[100], f[100];
bool cmp(ll x, ll y)
{
	return x > y;
}
int main()
{
	IOS;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <=2* n+1; j++) {
			if (j == 1) cout << "*";
			else if (j == n) cout << "*";
			else if (j == n + 2) cout << "*";
			else if (j == 2 * n + 1) cout << "*";
			else if (i == 1 && j > n + 1)cout << "*";
			else if (i == n && j < n) cout << "*";
			else cout << " ";
		}
		cout<<endl;
	}
	return 0;
}

I - Math Class

 Gym - 101466I 

题目链接https://codeforces.com/gym/101466/problem/I

J - Jeronimo's List

 Gym - 101466J 

题目链接https://codeforces.com/gym/101466/problem/J

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define ll long long
const int inf = 4e8 + 10;
const int mac = 3e7 + 10;
const int mod = 3e7;
int a[mac], vis[mac], ans[mac];
ll sum[mac];
int main()
{
	IOS;
	int n, m, q, x;
	cin >> n >> m >> q;
	for (int i = 1; i <= m; i++) {
		cin >> a[i];
		sum[i] = (sum[i - 1] + a[i]) % mod;
		vis[a[i]]++;
	}
	for (int i = m + 1; i <= n; i++) {
		a[i] = (sum[i - m + 1] - sum[i - m - 1]+mod) % mod;
		sum[i] = (a[i] + sum[i - 1]) % mod;
		vis[a[i]]++;
	}
	int p = 0;
	for (int i = 0; i <= mac; i++) {
		while (vis[i]) ans[++p] = i,vis[i]--;
	}
	for (int i = 1; i <= q; i++) {
		cin >> x;
		cout << ans[x] << endl;
	}
	return 0;
}

K - Random Numbers

 Gym - 101466K 

题目链接https://codeforces.com/gym/101466/problem/K

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ; 
const int mod = 1e9 + 7;
const int maxn = 1e5 + 7;
int a[maxn];
int prime[6] = {2, 3, 5, 7, 11, 13}, cnts[6], ans[6];
int vis[maxn];
struct node
{
    int to ,nxt;
}e[maxn << 1];

int tot,head[maxn];
int add_edge(int u , int v){
    e[++tot].to = v;
    e[tot].nxt = head[u];
    head[u] = tot;
}
int cnt = 0;
int in[maxn],ou[maxn];
void dfs(int x , int fa){
   in[x] = ++cnt;
    for(int i = head[x]; ~i ; i = e[i].nxt){
        if(fa != e[i].to){
            dfs(e[i].to , x);
        }
    }
    ou[x] = cnt; 
}

struct tree
{
    int l , r;
    int num[6] ;
}t[maxn << 2];

#define lc rt << 1
#define rc rt <<1|1

void push_up(int rt){
    for(int i = 0;i < 6 ; i++){
        t[rt].num[i] = t[lc].num[i] + t[rc].num[i] % mod;
    }
}

void build(int rt , int l ,int r){
    t[rt].l = l,t[rt].r = r;
    for(int i = 0;i < 6 ; i ++){
        t[rt].num[i] = 0;
    }
    if(l == r){
        for(int i = 0; i < 6; i++){
            if(vis[l] % prime[i] == 0){
                while(vis[l] % prime[i] == 0){
                    t[rt].num[i] ++;
                    vis[l] /= prime[i];
                }
            }
        }
        return;
    }
    int mid = (l + r ) >> 1;
    build(lc , l , mid);
    build(rc, mid + 1, r);
    push_up(rt);
}   

void update(int rt,int pos ,int x[]){
    if(t[rt].l == pos && pos == t[rt].r){
        for(int i = 0;i < 6; i++)
        t[rt].num[i] = t[rt].num[i] + x[i] % mod;
    return;
    }
    int mid = (t[rt].l + t[rt].r) >> 1;
    if(pos <= mid){
        update(lc,pos,x);
    }else {
        update(rc,pos , x);
    }
    push_up(rt);
}

int qpow(int x, int n) {
    int res = 1;
    while(n) {
        if(n & 1) res = (ll) res * x % mod;
        x = (ll)x * x % mod;
        n >>= 1;
    }
    return res;
}

void query(int rt ,int l ,int r,int ans[]){
    if(t[rt].l == l && t[rt].r == r){
        for(int i = 0;i < 6; i++){
            ans[i] += t[rt].num[i];
        }
        return;
    }
    int mid = (t[rt].l + t[rt].r) >> 1;
        if(r <= mid){
        query(lc,l,r,ans);
    }else if(l > mid){
        query(rc,l,r,ans);
    }else{
        query(lc,l,mid,ans);
        query(rc,mid + 1,r,ans);
    }
}


int main(int argc, char const *argv[])
{
    int n;
    cin >> n ;
    int x ;
    tot = x = 0;
    memset(head,-1,sizeof head);
    for(int i = 2;i <= n ; i ++){
        int u  , v;
        cin >> u >> v;
        u++, v ++;
        add_edge(u,v);
       // add_edge(v,u);
    }
    dfs(1,-1);
    int m ;
    //cin >> m ;
    for(int i = 1;i <= n ; i++){
        int p;
        cin >> p;
        vis[in[i]] = p;
    }
    build(1,1,n);
    int q;
    cin >> q;
    while(q--){
        string op;
        cin >> op;
        int a = 0, b = 0;
        if(op[0] == 'R'){
            cin >> a;
            a ++;
            for(int i = 0;i < 6 ; i++) ans[i] = 0;
                query(1,in[a],ou[a],ans);
            ll cnt1 = 1,cnt2 = 1;
            for(int i = 0;i < 6;i ++){
                cnt2 = (cnt2 * ((1 + ans[i]) % mod)) % mod;
                cnt1 = (cnt1 * qpow(prime[i], ans[i])) % mod;
            
            }
            cout << cnt1 << " " << cnt2 << endl;
        }else{
            cin >> a >> b;
            a ++;
            for(int i = 0;i < 6; i ++){
                cnts[i] = 0;
                if(b % prime[i] == 0){
                    while(b % prime[i] == 0){
                        cnts[i]++;
                        b /= prime[i];
                    }
                }
            }
            update(1,in[a],cnts);
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值