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;
}
View Code

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;
}
View Code

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;
}
View Code

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;
}
View Code

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;
}
View Code

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;
}
View Code

 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;
}
View Code

 

posted @ 2019-07-23 21:10  wrjlinkkkkkk  阅读(510)  评论(0编辑  收藏  举报