CSUST 8.3 早训
Posted dwvictor
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CSUST 8.3 早训相关的知识,希望对你有一定的参考价值。
A - Settlers‘ Training
题意
给你一串数字,相同的数字为一组,每次可以给一组中的一个数字加一,问这一串数字全变成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
【题意】
给你一个长度为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;
题意
看这个数的数据类型(都是整树,且为正数)。
解题思路
首先判断长度。
当长度和极值的长度相同时,在用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;
题意
雨可以向两边蔓延,如果往边上走的高度是非递增的。
解题思路
暴力,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;
给若干个文件路径,问子文件夹以及子文件最多为多少 模拟题,可以直接用文件的绝对路径来表示一个文件
题解
这样就不用担心不同路径文件的重名问题,也不用建树了
其次子文件夹和子文件数最多的肯定是根目录下的文件夹
用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;
题解
要求构造一个长度为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);
以上是关于CSUST 8.3 早训的主要内容,如果未能解决你的问题,请参考以下文章