The 2019 University of Jordan Collegiate Programming Contest

链接:https://codeforc.es/gym/102267

A. Picky Eater

直接比较

int main(){
    int x ,y;
    scanf("%d %d" ,&x ,&y);
    if(x>=y){
        return printf("1"),0;
    }
    else return printf("0"),0;
    return 0;
}

B. Primes

素数筛,log判断

int prime[maxn],num_prime = 0;
int vis[maxn];
void is_prime(int N){
    for(int i=2;i<=N;i++){
        if(!vis[i]){
            prime[num_prime++] = i;
            vis[i] = i;
        }
        for(int j=0;j<num_prime&&i*prime[j]<=N;j++){
            vis[i*prime[j]] = prime[j];
            if(!(i%prime[j])){
                break;
            }
        }
    }
    return;
}
int n;
int main(){
    scanf("%d", &n);
    is_prime(n);
    for(int i = 0; i < num_prime; i++){
        int j = prime[i];
        int p = lower_bound(prime,prime+num_prime,n-j)-prime;
        if(prime[p]==n-j){
            return printf("%d %d",j,n-j),0;
        }

    }
    printf("-1");
    return 0;
}

C. Matryoshka Dolls

一个循环

int x,y;
int main(){
    scanf("%d %d", &x, &y);
    int ans = 0;
    while(x){
        ans++;
        x/=y;
    }printf("%d",ans);
    return 0;
}

D. Robots Easy

12*12,直接rand乱跑

#include<iostream>
#include<cstdio>
#include<algorithm>
//#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>

#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1

using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
const int mod = 998244353;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
//const db pi = acos(-1.0);

int x,y;
int a[111][111];
vector<char>ans;
int dx,dy;
inline int Rand(){
    static int seed = 2333;
    return seed = (int)((((seed ^ 998244353) + 19260817ll) * 19890604ll) % 1000000007);
}
int main(){
    int t;
    scanf("%d", &t);
    a[6][6]=a[6][7]=a[7][6]=a[7][7]=1;
    a[9][2]=a[9][3]=a[10][2]=1;
    a[9][10]=a[9][11]=a[10][11]=1;
    a[3][3]=a[3][10]=a[10][3]=a[10][10]=2;
    while(t--){
        ans.clear();
        scanf("%d %d" ,&x ,&y);
        while(a[x][y]!=2){
            //printf("%d %d\n",x,y);
            int op;
            while(op=rand()%5){
                dx=dy=0;
                char ch;
                if(op==1){dx=-1;ch=‘U‘;}
                if(op==2){dx=1;ch=‘D‘;}
                if(op==3){dy=-1;ch=‘L‘;}
                if(op==4){dy=1;ch=‘R‘;}
                if(op==0)continue;
                //printf("      %d\n",op);
                if(x+dx>=1&&x+dx<=12&&y+dy>=1&&y+dy<=12){
                    if(a[x+dx][y+dy]==1)continue;
                    x+=dx;y+=dy;
                    ans.pb(ch);
                    break;
                }
                else continue;
            }
        }
        printf("%d\n",ans.size());
        for(int i = 0; i < (int)ans.size(); i++){
            printf("%c",ans[i]);
        }printf("\n");

    }
    return 0;
}

H. Circle of Polygon

一个公式

double v,s;
int main(){
    scanf("%lf %lf", &v, &s);
    printf("%.9lf",1.0/2.0*pi*s*s/(1.0-cos(2*pi/v)));

    return 0;
}

I. Ultimate Army

左括号之后一定跟一个数,遇到左括号,下一个数的sup就是栈顶,遇到数字入栈,遇到右括号出栈

int n;
char a[maxn];
stack<int>s;
vector<int>v;
int ans[maxn];
int main(){
    scanf("%d", &n);
    scanf("%s",a+1);
    int len = strlen(a+1);
    int tmp = 0;
    int gao = 0;
    for(int i = 1; i <= len; i++){
        if(a[i]>=‘0‘&&a[i]<=‘9‘){
            tmp*=10;
            tmp+=a[i]-‘0‘;
        }
        else{
            if(tmp!=0)v.pb(tmp);
            tmp=0;
        }
        if(a[i]==‘(‘)v.pb(-1);
        else if(a[i]==‘)‘)v.pb(-2);
    }
    for(int i = 0; i < (int)v.size(); i++){
        if(v[i]>0){
            if(gao)ans[v[i]]=s.top();
            s.push(v[i]);
            gao=0;
        }
        else if(v[i]==-1){
            gao=1;
        }
        else if(v[i]==-2){
            s.pop();
        }
    }
    for(int i = 1; i <= n; i++){
        printf("%d ",ans[i]);
    }
    return 0;
}

K. Birthday Puzzle

2^20暴力dfs维护答案即可

ll ans;
int n;
int a[maxn];
void dfs(int x, int now){
    if(x==n+1){
        ans+=now;
        return;
    }
    dfs(x+1,now|a[x]);
    dfs(x+1,now);
}
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }
    dfs(1,0);
    printf("%lld",ans);
    return 0;
}

原文地址:https://www.cnblogs.com/wrjlinkkkkkk/p/11234506.html

时间: 2024-10-08 19:48:35

The 2019 University of Jordan Collegiate Programming Contest的相关文章

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018 Problem A. Can Shahhoud Solve it? Problem B. Defeat the Monsters Problem C. UCL Game Night Problem

ACM International Collegiate Programming Contest, JUST Collegiate Programming Contest (2018)

ACM International Collegiate Programming Contest, JUST Collegiate Programming Contest (2018) B. New Assignment 有n个人(1?≤?n?≤?104),有男有女,每个人都有一个id,现在这n个人分成学习互助小组,有三种组队模式,一个男人一组,一个女人一组,一男一女一组,如果要一男一女一组,那么这两人id的gcd要>1.保证任意三个人的gcd=1.求小组的组数最少是多少? 看起来是一个很裸的二

Nordic Collegiate Programming Contest 2015? B. Bell Ringing

Method ringing is used to ring bells in churches, particularly in England. Suppose there are 6 bells that have 6 different pitches. We assign the number 1 to the bell highest in pitch, 2 to the second highest, and so on. When the 6 bells are rung in

2018 German Collegiate Programming Contest (GCPC 18)

2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include <cstdlib> #include <iomanip> #include <bit

2018 ACM-ICPC, Syrian Collegiate Programming Contest

2018 ACM-ICPC, Syrian Collegiate Programming Contest A Hello SCPC 2018! 水题 B Binary Hamming 水题 C Portals 思路:并查集维护连通性 代码: //#pragma GCC optimize(3) //#pragma comment(linker, "/STACK:102400000,102400000") //c++ // #pragma GCC diagnostic error &quo

(寒假GYM开黑)2018 German Collegiate Programming Contest (GCPC 18)

layout: post title: 2018 German Collegiate Programming Contest (GCPC 18) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces 传送门 付队博客 C.Coolest Ski Route (记忆化搜索) 题意 给出一个有向图,求出一个权值最长的链, 题解 暴力dfs会超时,所以直接储存每个起点能走到的最远距离 #include<

(寒假GYM开黑)2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)

layout: post title: 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces 传送门 付队! B.Baby Bites (签到模拟) 按照题意模拟就行了 int a[maxn]; string s; int main() { std::ios::syn

(寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest

layout: post title: (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces 传送门 付队! 许老师! Hello SCPC 2018! (签到) #include<bits/stdc++.h> using namespace std; typedef

(寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

layout: post title: (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces 传送门 付队! 许老师! B.Buildings (polya定理) 题意 B:给你m面墙,每面墙是n*n的格子,你有c种颜色,问你有多少种涂色方案.用po