CSUST 8.3 早训

A - Settlers‘ Training

CodeForces - 63B

题意

给你一串数字,相同的数字为一组,每次可以给一组中的一个数字加一,问这一串数字全变成K需要多少步?

题解

模拟

C++代码

/**
/*@author Victor
/*language C++
*/
//#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
//#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int , ll>
#define pli pair<ll,int>
#define pdl pair<double,ll>
#define pld pair<ll,double>
#define pdd pair<double,double>
#define iput(n) scanf("%d",&n)
#define iiput(a,n) scanf("%d%d",&a,&n)
#define iiiput(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dput(n) scanf("%lf",&n)
#define llput(n) scanf("%lld",&n)
#define cput(n) scanf("%s",n)
#define puti(n) printf("%d\n",n)
#define putll(n) printf("%lld\n",n)
#define putd(n) printf("%lfd\n",n)
#define _cls(n) memset(n,0,sizeof(n))
#define __cls(n) memset(n,0x3f,sizeof(n))
#define lc rt << 1
#define rc rt <<1|1
#define debug(x) cout << "[ " << x << " ]" << endl
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
//map<ll,ll>mp;
//set<ll>st;
//stack<>st;
//queue<>Q;
#define F first
#define S second
#define pb push_back
#define PB push_back
#define MP make_pair
#define ALL(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
/***********************************************/
//加速输入挂
# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
//求二进制中1的个数
//__builtin_popcount(n);
//求2^k
//#define (ll)Pow(2,k) (1LL<<k)
#define to_1(n) __builtin_popcount(n)
//树状数组
#define lowbit(x) (x&-x)
//#ifdef DEBUG
#define fin freopen("input.in", "r", stdin)
#define fout freopen("output.out", "w", stdout);
//#endif
//手动扩栈
#pragma comment(linker,"/STACK:102400000,102400000")
const int maxn = 2e5 + 7;
int n  , m ;

int a[maxn];
//map<int,int> mp;
int b[maxn];
int main(int argc, char const *argv[])
{
    cin >> n >> m;  int sum = 0;
    for(int i = 1;i <= n ;i ++) cin >>a[i],sum += a[i];
        sort(a + 1 ,a + n  + 1);
    int ans = 0;
    while ( n * m > sum){
        ans ++;
        int j = 0;

                //b[i] = a[i];
                // if(a[i] && j == 0){
                //     j ++;
                //     a[i] --;
                //     sum ++;
                // }
                // else if(a[i] == n){
                //     sum ++;
                // }
        for(int i = 1;i <= n ; i++) b[i] = a[i];
            if(b[1] < m) {
                sum ++;
                b[1]++;
            }
            for(int i = 2;i <= n;i ++){
                if(a[i] == a[i-1] || a[i] == m) continue;
                b[i] ++;
                sum ++;
            }
            sort(b + 1, b + n + 1);
            for(int i = 1;i <= n ;i ++) a[i] = b[i];

        }

    cout << ans << endl;
    return 0;
}

B - Bulls and Cows

CodeForces - 63C

【题意】

给你一个长度为4的数字序列(每个数字都在0~9之间,且不重复出现)
现在让你猜这个长度为4的序列是什么.
猜了之后对方会告诉有几个数字是位置和数字都正确的(猜的数字序列有顺序)
以及有几个数字是数字出现了但是位置不正确.
即给你两个反馈。
现在给你n个猜的过程(猜的4个数字以及对应的两个反馈)
问你是否能唯一的确定一个4位数字的答案

【题解】

列举出来最后的4位数的所有可能。
对于每一种可能 将其对这n个猜的过程验证一遍》
如果验证通过,那么递增sum
最后如果sum==1则说明存在唯一的一个可能.
sum==0说明没有任何一个可能,则数据有错
sum>1则说明需要更多的数据才能确定是哪一个.

C++代码

/**
/*@author Victor
/*language C++
*/
//#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
//#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int , ll>
#define pli pair<ll,int>
#define pdl pair<double,ll>
#define pld pair<ll,double>
#define pdd pair<double,double>
#define iput(n) scanf("%d",&n)
#define iiput(a,n) scanf("%d%d",&a,&n)
#define iiiput(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dput(n) scanf("%lf",&n)
#define llput(n) scanf("%lld",&n)
#define cput(n) scanf("%s",n)
#define puti(n) printf("%d\n",n)
#define putll(n) printf("%lld\n",n)
#define putd(n) printf("%lfd\n",n)
#define _cls(n) memset(n,0,sizeof(n))
#define __cls(n) memset(n,0x3f,sizeof(n))
#define lc rt << 1
#define rc rt <<1|1
#define debug(x) cout << "[ " << x << " ]" << endl
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
//map<ll,ll>mp;
//set<ll>st;
//stack<>st;
//queue<>Q;
#define F first
#define S second
#define pb push_back
#define PB push_back
#define MP make_pair
#define ALL(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
/***********************************************/
//加速输入挂
# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
//求二进制中1的个数
//__builtin_popcount(n);
//求2^k
//#define (ll)Pow(2,k) (1LL<<k)
#define to_1(n) __builtin_popcount(n)
//树状数组
#define lowbit(x) (x&-x)
//#ifdef DEBUG
#define fin freopen("input.in", "r", stdin)
#define fout freopen("output.out", "w", stdout);
//#endif
//手动扩栈
#pragma comment(linker,"/STACK:102400000,102400000")
const int maxn = 2e5 + 7;
int n  , m ;

int a[maxn];
//map<int,int> mp;
int b[maxn];

struct node
{
    int str;
    int a ,  b;
    int f1,f2,f3,f4;
}nod[11];

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    for(int i = 1;i <= n ; i ++){
        cin >> nod[i].str >> nod[i].a >> nod[i].b;
    }
    for(int i = 1;i <= n;i ++){

            nod[i].f1 = nod[i].str % 10;
            nod[i].f2 = (nod[i].str / 10 ) % 10;
            nod[i].f3 =  (nod[i].str / 100 ) % 10;
            nod[i].f4 =  (nod[i].str / 1000 ) % 10;

    }
    int flag = 0;
    int sum = 0;
    string str;
    for(int i = 0;i <= 9;i ++){

        for(int j = 0;j <= 9;j ++){

            for(int k = 0;k <= 9;k ++){
                for(int p = 0;p <= 9;p ++){
                    int ans = 0;
                    if(i != j && i != k && i != p && j != k && j != p && k != p)
                    for(int q = 1;q <= n; q ++){
                        int a = 0, b = 0;
                        if(nod[q].f1 == i) {
                            a ++;
                        }
                        if(nod[q].f2 == j) a ++;
                        if(nod[q].f3 == k)a ++;
                        if(nod[q].f4 == p) a ++;
                        if(nod[q].f1 == j || nod[q].f1 ==k || nod[q].f1 == p) b++;
                        if(nod[q].f2 == i || nod[q].f2 ==k || nod[q].f2 == p) b++;
                        if(nod[q].f3 == j || nod[q].f3 ==i || nod[q].f3 == p) b++;
                        if(nod[q].f4 == j || nod[q].f4 ==k || nod[q].f4 == i) b++;
                        if(a == nod[q].a && b == nod[q].b) ans ++;
                    }
                    if(ans == n) {
                        str.push_back(p + ‘0‘);
                        str.push_back(k + ‘0‘);
                        str.push_back(j + ‘0‘);
                        str.push_back(i + ‘0‘);

                        //sum = p * 1000 + k * 100 + j * 10 + i;
                        flag ++;
                       // break;
                    }
                }
            }
        }
    }
    if(flag == 1) cout << str << endl;
    else if(flag > 1)cout << "Need more data" << endl;
    else cout << "Incorrect data" << endl;
    return 0;
}

C - Petya and Java

CodeForces - 66A

题意

看这个数的数据类型(都是整树,且为正数)。

解题思路

首先判断长度。 
当长度和极值的长度相同时,在用strcmp判断。

C++代码

/**
/*@author Victor
/*language C++
*/
//#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
//#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int , ll>
#define pli pair<ll,int>
#define pdl pair<double,ll>
#define pld pair<ll,double>
#define pdd pair<double,double>
#define iput(n) scanf("%d",&n)
#define iiput(a,n) scanf("%d%d",&a,&n)
#define iiiput(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dput(n) scanf("%lf",&n)
#define llput(n) scanf("%lld",&n)
#define cput(n) scanf("%s",n)
#define puti(n) printf("%d\n",n)
#define putll(n) printf("%lld\n",n)
#define putd(n) printf("%lfd\n",n)
#define _cls(n) memset(n,0,sizeof(n))
#define __cls(n) memset(n,0x3f,sizeof(n))
#define lc rt << 1
#define rc rt <<1|1
#define debug(x) cout << "[ " << x << " ]" << endl
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
//map<ll,ll>mp;
//set<ll>st;
//stack<>st;
//queue<>Q;
#define F first
#define S second
#define pb push_back
#define PB push_back
#define MP make_pair
#define ALL(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
/***********************************************/
//加速输入挂
# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
//求二进制中1的个数
//__builtin_popcount(n);
//求2^k
//#define (ll)Pow(2,k) (1LL<<k)
#define to_1(n) __builtin_popcount(n)
//树状数组
#define lowbit(x) (x&-x)
//#ifdef DEBUG
#define fin freopen("input.in", "r", stdin)
#define fout freopen("output.out", "w", stdout);
//#endif
//手动扩栈
#pragma comment(linker,"/STACK:102400000,102400000")
const int maxn = 2e5 + 7;
int n  , m ;

int a[maxn];
//map<int,int> mp;
int b[maxn];

int main()
{
    long double n;
    cin>>n;
    if(n<=127)
    {
        cout<<"byte"<<endl;
    }
    else if(n<=32767)
    {
        cout<<"short"<<endl;
    }
    else if(n<=2147483647)
    {
        cout<<"int"<<endl;
    }
    else if(n<=9223372036854775807)
    {
        cout<<"long"<<endl;
    }
    else
    {
        cout<<"BigInteger"<<endl;
    }
    return 0;
}

D - Petya and Countryside

CodeForces - 66B

题意

雨可以向两边蔓延,如果往边上走的高度是非递增的。

解题思路

暴力,O(n^2)。

C++代码

/**
/*@author Victor
/*language C++
*/
//#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
//#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int , ll>
#define pli pair<ll,int>
#define pdl pair<double,ll>
#define pld pair<ll,double>
#define pdd pair<double,double>
#define iput(n) scanf("%d",&n)
#define iiput(a,n) scanf("%d%d",&a,&n)
#define iiiput(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dput(n) scanf("%lf",&n)
#define llput(n) scanf("%lld",&n)
#define cput(n) scanf("%s",n)
#define puti(n) printf("%d\n",n)
#define putll(n) printf("%lld\n",n)
#define putd(n) printf("%lfd\n",n)
#define _cls(n) memset(n,0,sizeof(n))
#define __cls(n) memset(n,0x3f,sizeof(n))
#define lc rt << 1
#define rc rt <<1|1
#define debug(x) cout << "[ " << x << " ]" << endl
//priority_queue <int,vector<int>,greater<int> > Q;//??????
//priority_queue<int>Q;//??
//map<ll,ll>mp;
//set<ll>st;
//stack<>st;
//queue<>Q;
#define F first
#define S second
#define pb push_back
#define PB push_back
#define MP make_pair
#define ALL(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
/***********************************************/
//?????
# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
//?????1???
//__builtin_popcount(n);
//?2^k
//#define (ll)Pow(2,k) (1LL<<k)
#define to_1(n) __builtin_popcount(n)
//????
#define lowbit(x) (x&-x)
//#ifdef DEBUG
#define fin freopen("input.in", "r", stdin)
#define fout freopen("output.out", "w", stdout);
//#endif
//????
#pragma comment(linker,"/STACK:102400000,102400000")
const int maxn = 2e5 + 7;
int n  , m ;

int a[maxn];
//map<int,int> mp;
int b[maxn];

int main(int argc, char const *argv[])
{
    int n ;
    cin >> n ;
    for(int i =1;i <=  n;i ++ ){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 1;i <= n ;i ++){
        int sum = 0;
        int l = i - 1, r = i + 1;
        if(i == 1)
        while(a[r] <= a[r - 1] && r != n + 1) sum ++,r ++;
        else if(i == n)
            while(a[l] <= a[l + 1] && l != 0) sum ++, l --;
        else {
            while(a[r] <= a[r - 1] && r != n + 1) sum ++,r ++;
            while(a[l] <= a[l + 1] && l != 0) sum ++,l --;
        }
        ans = max(ans,sum + 1);
    }
    cout << ans << endl;
    return 0;
}

E - Petya and File System

CodeForces - 66C

题意

给若干个文件路径,问子文件夹以及子文件最多为多少 模拟题,可以直接用文件的绝对路径来表示一个文件

题解

这样就不用担心不同路径文件的重名问题,也不用建树了 
其次子文件夹和子文件数最多的肯定是根目录下的文件夹 
用set维护一下这些文件夹的情况即可,set的好处是不用去重

C++代码

/**
/*@author Victor
/*language C++
*/
//#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int , ll>
#define pli pair<ll,int>
#define pdl pair<double,ll>
#define pld pair<ll,double>
#define pdd pair<double,double>
#define iput(n) scanf("%d",&n)
#define iiput(a,n) scanf("%d%d",&a,&n)
#define iiiput(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dput(n) scanf("%lf",&n)
#define llput(n) scanf("%lld",&n)
#define cput(n) scanf("%s",n)
#define puti(n) printf("%d\n",n)
#define putll(n) printf("%lld\n",n)
#define putd(n) printf("%lfd\n",n)
#define _cls(n) memset(n,0,sizeof(n))
#define __cls(n) memset(n,0x3f,sizeof(n))
#define lc rt << 1
#define rc rt <<1|1
#define debug(x) cout << "[ " << x << " ]" << endl
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
//map<ll,ll>mp;
//set<ll>st;
//stack<>st;
//queue<>Q;
#define F first
#define S second
#define pb push_back
#define PB push_back
#define MP make_pair
#define ALL(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
/***********************************************/
//加速输入挂
# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
//求二进制中1的个数
//__builtin_popcount(n);
//求2^k
//#define (ll)Pow(2,k) (1LL<<k)
#define to_1(n) __builtin_popcount(n)
//树状数组
#define lowbit(x) (x&-x)
//#ifdef DEBUG
#define fin freopen("input.in", "r", stdin)
#define fout freopen("output.out", "w", stdout);
//#endif
//手动扩栈
#pragma comment(linker,"/STACK:102400000,102400000")
const int maxn = 2e5 + 7;
int n  , m ;

int a[maxn];
//map<int,int> mp;
int b[maxn];

map<string,set<string> > folder,files;

int main(int argc, char const *argv[])
{
    string str , rt;
    while(cin >> str){
        int ans = 0;
        for(int i = 0; i < str.size() ; i ++){
            if(str[i] == ‘\\‘){
                ans ++;
                if(ans == 2){
                    rt = str.substr(0,i);
                }
                else if(ans > 2) folder[rt].insert(str.substr(0,i));
            }

        }
         files[rt].insert(str);
    }
    int maxx1 = 0,maxx2 = 0;
        for(auto au : folder){
            maxx1 = max(maxx1,(int)au.second.size());
        }
        for(auto au : files){
            maxx2 = max(maxx2,(int)au.second.size());
        }

        cout << maxx1 << " " << maxx2 << endl;

    return 0;
}

F - Petya and His Friends

CodeForces - 66D

题解

要求构造一个长度为n的正整数序列ai,使得对于∀i≠j,gcd(ai,aj)>1,且gcd(a1,a2,...,an)=1
n=2显然无解,n>2时,取前nn个素数p1,p2,...,pn令ai=∏j≠ipj,简单验证知a1,a2,...,an满足条件,数字很大要用到高精度

解法二

构造出前3个15 10 6 剩下的为 i * 6即可

C++代码一

/**
/*@author Victor
/*language C++
*/
//#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int , ll>
#define pli pair<ll,int>
#define pdl pair<double,ll>
#define pld pair<ll,double>
#define pdd pair<double,double>
#define iput(n) scanf("%d",&n)
#define iiput(a,n) scanf("%d%d",&a,&n)
#define iiiput(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dput(n) scanf("%lf",&n)
#define llput(n) scanf("%lld",&n)
#define cput(n) scanf("%s",n)
#define puti(n) printf("%d\n",n)
#define putll(n) printf("%lld\n",n)
#define putd(n) printf("%lfd\n",n)
#define _cls(n) memset(n,0,sizeof(n))
#define __cls(n) memset(n,0x3f,sizeof(n))
#define lc rt << 1
#define rc rt <<1|1
#define debug(x) cout << "[ " << x << " ]" << endl
//priority_queue <int,vector<int>,greater<int> > Q;//优先队列递增
//priority_queue<int>Q;//递减
//map<ll,ll>mp;
//set<ll>st;
//stack<>st;
//queue<>Q;
#define F first
#define S second
#define pb push_back
#define PB push_back
#define MP make_pair
#define ALL(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
/***********************************************/
//加速输入挂
# define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
//求二进制中1的个数
//__builtin_popcount(n);
//求2^k
//#define (ll)Pow(2,k) (1LL<<k)
#define to_1(n) __builtin_popcount(n)
//树状数组
#define lowbit(x) (x&-x)
//#ifdef DEBUG
#define fin freopen("input.in", "r", stdin)
#define fout freopen("output.out", "w", stdout);
//#endif
//手动扩栈
#pragma comment(linker,"/STACK:102400000,102400000")
const int maxn = 2e5 + 7;
int n  , m ;

int a[maxn];
//map<int,int> mp;
int b[maxn];
int cnt,prime[N],p[N];
void isprime()
{
    cnt = 0;
    memset(prime,true,sizeof(prime));
    for(int i=2; i<N; i++)
    {
        if(prime[i])
        {
            p[cnt++] = i;
            for(int j=i+i; j<N; j+=i)
                prime[j] = false;
        }
    }
}
long long sum[100];
int main(int argc, char const *argv[])
{
    int n ;
    isprime();
    cin >> n ;
    int flag = 1;
    if(n == 2)flag = 0;
    sum[0] = 1;
    for(int i = 1;i <= 50 ; i++){
        sum[i] = p[i-1];
    }
    if(flag){
        cout << 15 << endl << 10 << endl << 6 << endl;
        for(int i = 4 ;i <= n; i ++) cout << i * 6 << endl;
    }

        else
        cout << -1 << endl;

        return 0;
    }

java代码二

 //package ce;

import java.lang.invoke.ConstantCallSite;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

import javax.swing.InputMap;
import javax.swing.undo.AbstractUndoableEdit;

public class Main{

static int maxn = (int) (1e5 + 7);
static int p[] = new int [maxn];
static int prime[] = new int [maxn];
static void isprime()
{
    //int b[] = new int[maxn];
    int cnt;

   // p[] = new int [maxn];
    cnt = 0;
    Arrays.fill(prime,1);
    for(int i=2; i< maxn; i++)
    {
        if(prime[i] == 1)
        {
            p[cnt++] = i;
            for(int j=i+i; j<maxn; j+=i)
                prime[j] = 0;
        }
    }
}

private Object sizeof(int[] prime) {
    // TODO Auto-generated method stub
    return null;
}
static BigInteger sum[] = new BigInteger[100];
public static void  main(String[] args) {

     // int n ;
      isprime();
      Scanner a = new Scanner(System.in);
      int n = a.nextInt();
        int flag = 1;
        if(n == 2)flag = 0;
        //sum[0] = 1;
        for(int i = 1;i <= 50 ; i++){
          //  Object[] p;
            sum[i] = BigInteger.valueOf(p[i-1]);
        }
        if(flag == 1)
        for(int i = 1;i <= n ;i ++){
            BigInteger ans = BigInteger.valueOf(1);
            for(int j = 1;j <= n;j ++){
                if(i!=j) ans = ans.multiply(sum[j]);
            }
            if (flag == 1) {
                System.out.println(ans);
            }

        }else System.out.print(-1);

}
}

原文地址:https://www.cnblogs.com/DWVictor/p/11296162.html

时间: 2024-08-30 12:52:47

CSUST 8.3 早训的相关文章

CSUST 8.5 早训

## Problem A A - Meeting of Old Friends CodeForces - 714A 题意: 解题说明:此题其实是求两段区间的交集,注意要去除掉交集中的某个点. 题解: C++版本一 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<string> #include<cmath> int m

CSUST 8.4 早训

## Problem A A - Memory and Crow CodeForces - 712A 题意: 分析可得bi=ai+ai+1 题解: 分析可得bi=ai+ai+1 C++版本一 #include<bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; int a[maxn]; int main(int argc, char const *argv[]) { int n; cin >> n ; for(

C - Ordering Pizza CodeForces - 867C 贪心 经典

C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先假设每个人都可以吃到他喜欢的,就是先求出答案,然后按照b-a 排序,分别放入两个优先队列里面, 如果b>a 那就吃第二块,否则就吃第一块,求出num,注意优先队列按照从小到达排序. num1记录第一块吃的数量,num2记录第二块吃的数量. num1%=s,num2%=s  如果num1+num2的数

B - Save the problem! CodeForces - 867B 构造题

B - Save the problem! CodeForces - 867B 这个题目还是很简单的,很明显是一个构造题,但是早训的时候脑子有点糊涂,想到了用1 2 来构造, 但是去算这个数的时候算错了... 用1 2 来构造 可以先枚举一些数来找找规律. 1 1 2 2 3 1 1 1    2 1 1 4 .... 可以发现每一个数都是 n/2+1 的可能, 所以反过来推过去就是 (s-1)*2  或者(s-1)*2+1 这个(s-1)*2+1的答案才是正确答案 因为 这个s可以==1 #i

哈佛图书馆自习室墙上的训言——觉得为时已晚的时候,恰恰是最早的时候——不是缺乏时间,而是缺乏努力

哈佛图书馆自习室墙上的训言1.此刻打盹,你将做梦:而此刻学习,你将圆梦. 2.我荒废的今日,正是昨日殒身之人祈求的明日. 3.觉得为时已晚的时候,恰恰是最早的时候. 4.勿将今日之事拖到明日. 5.学习时的苦痛是暂时的,未学到的痛苦是终生的. 6.学习这件事,不是缺乏时间,而是缺乏努力. 7.幸福或许不排名次,但成功必排名次. 8.学习并不是人生的全部.但,既然连人生的一部分——学习也无法征服,还能做什么呢? 9.请享受无法回避的痛苦. 10.只有比别人更早.更勤奋地努力,才能尝到成功的滋味.

山西高平地域文化导入美术设计实训项目的实践

地域文化,是指某个地域的人们在特定的范围内,在自然环境的基础上,在长期的生产生活中创造的.人类活动的产物.山西高平是神农炎帝的故里,长平之战的发生地,是一个有着很深文化积淀的新兴城市,行政区域是国土面积的万分之一,却浓缩了中国五千年文化的精髓.本文通过对山西高平丰富的历史文化资源的调查研究,探讨如何将地域文化元素导入中职美术设计专业的实训项目教学过程,论证典型地域文化元素在中职美术设计教育中的独特作用,并以此作为教学实训素材,依托带有典型地域文化特征的企业真实案例,结合教育教学实践,探索中职美术

伊斯兰教义最早的中文记载

最早用中文记载伊斯兰教义的文献是唐人杜环的<经行记>. <经行记>是杜环因怛罗斯战役失败被俘后,居大食12年历游各地的闻见录.可惜此书早佚.所幸<通典>中还存有该书的几条引文.从这些引文中,我们可以得知,<经行记>对伊斯兰教义的最高信仰和礼拜斋戒等重要功课都记述得正确而具体,这不只在<经行记>以前没有过,就是在<经行记>之后的唐宋记载中,也没有过. 据<通典>卷193的引文,<经行记>说,大食国一名叫“亚俱罗”

哈佛图书馆上的训言

哈佛图书馆上的训言(转) 1.此刻你打盹,你将做梦:而此刻你学习,你将圆梦. 2.我荒废的今日,正是昨天殒身之人祈求的明日. 3.觉得为时已晚的时候,恰恰是最早的时候. 4.勿将今日之事拖到明日. 5.学习时的痛苦是暂时的,未学到的痛苦是终生的. 6.学习这件事,不是缺乏时间,而是缺乏努力. 7.幸福或许不排名次,但成功必排名次. 8.学习并不是人生的全部.但既然连人生的一部分---学习也无法征服,还能做什么呢? 9.请享受无法回避的痛苦. 10.只有比别人更早,更勤奋的努力,才能尝到成功的滋味

产品黑客特训营——产品构建&amp;运营实战【7月6-9日姜大胡子】

<产品黑客>--产品构建&运营实战,由大胡子老师携手跨界引导师团队带来三天.两晚.四次线上分享,内容包含产品构建方法.产品运营.修炼全脑思维.视觉设计.跨界引导等,以及奔驰.阿里巴巴经典案例,为您呈现一种全新的课堂体验,7月6-8日 北京 不见不散. 互联网时代, 如何才能构建一款优秀的产品? 下?个趋势到底在哪里? 怎样才能构建?个高粘度的线上社群? 如何完成从0到1的冷启动? 『互联网+』,到底+的是什么?怎么+? 如何洞察用户心理,让用户无法不买? 怎么才能做到有效传播? 如何撰