"字节跳动杯"2018中国大学生程序设计竞赛-女生专场
口算训练
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <map> 7 #include <cmath> 8 #include <vector> 9 10 #define Faster ios::sync_with_stdio(false),cin.tie(0) 11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) 12 #define Close fclose(stdin),fclose(stdout) 13 const int maxn = 1e5 + 5; 14 using namespace std; 15 const int MOD = 1e9+7; 16 typedef long long ll; 17 18 vector<int> g[maxn]; 19 //下标肯定是从小到大按顺序的 20 21 void res(int id, int x){ 22 for(int i = 2;i*i <= x;i++){ 23 while(x%i == 0){ 24 g[i].push_back(id); 25 x /= i; 26 } 27 } 28 if(x > 1) 29 g[x].push_back(id); 30 } 31 32 int query(int l,int r, int x){ 33 return upper_bound(g[x].begin(), g[x].end(), r) - lower_bound(g[x].begin(),g[x].end(), l); 34 } 35 36 void init(){ 37 for(int i = 0;i < maxn;i++) 38 g[i].clear(); 39 } 40 41 int main(){ 42 // Faster; 43 int t; 44 // cin >> t; 45 scanf("%d", &t); 46 while(t--){ 47 init(); 48 int n, q; 49 scanf("%d%d", &n, &q); 50 for(int i = 1;i <= n;i++){ 51 int x; 52 // cin >> x; 53 scanf("%d", &x); 54 res(i, x); 55 } 56 while(q--){ 57 int l, r, d, num; 58 // cin >> l >> r >> d; 59 scanf("%d%d%d", &l, &r, &d); 60 bool ok = true; 61 for(int i = 2;i*i <= d;i++){ 62 int cnt = 0; 63 while(d%i == 0){ 64 cnt++; 65 d /= i; 66 } 67 //因子为i 的数目 大于(l,r)中i 的个数 68 num = query(l, r, i); 69 if(cnt > num){ 70 ok = false; 71 break; 72 } 73 } 74 if(ok && d > 1){ 75 num = query(l, r, d); 76 if(num == 0) 77 ok = false; 78 } 79 if(ok) 80 // cout << "Yes" << endl; 81 printf("Yes\n"); 82 else 83 // cout << "No" << endl; 84 printf("No\n"); 85 } 86 } 87 return 0; 88 }
缺失的数据范围
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <map> 7 #include <cmath> 8 #include <vector> 9 10 #define Faster ios::sync_with_stdio(false),cin.tie(0) 11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) 12 #define Close fclose(stdin),fclose(stdout) 13 const int maxn = 1e4 + 5; 14 using namespace std; 15 const int MOD = 1e9+7; 16 typedef unsigned long long ll; 17 18 int a, b; 19 ll k; 20 21 bool check(ll x){ 22 long double ans = 1; 23 for(int i = 0;i < a;i++){ 24 ans *= x; 25 if(ans > k) 26 return false; 27 } 28 ll bb = ceil(log2(x)); 29 for(int i = 0;i < b;i++){ 30 ans *= bb; 31 if(ans > k) 32 return false; 33 } 34 return true; 35 } 36 37 int main(){ 38 Faster; 39 int n; 40 cin >> n; 41 while(n--){ 42 cin >> a >> b >> k; 43 ll l = 1; 44 ll r = k; 45 while(l <= r){ 46 ll mid = (l+r)/2; 47 if(check(mid)){ 48 l = mid+1; 49 } 50 else{ 51 r = mid-1; 52 } 53 } 54 cout << r << endl; 55 } 56 return 0; 57 }
赛题分析
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <map> 7 #include <cmath> 8 #include <vector> 9 10 #define Faster ios::sync_with_stdio(false),cin.tie(0) 11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) 12 #define Close fclose(stdin),fclose(stdout) 13 const int maxn = 1e4 + 5; 14 using namespace std; 15 const int MOD = 1e9+7; 16 typedef long long ll; 17 18 #define INF 0xfffffff 19 20 int main(){ 21 Faster; 22 int t; 23 cin >> t; 24 int cnt = 1000; 25 while(t--){ 26 int n, m; 27 cin >> n >> m; 28 int Min1 = INF; 29 int Min2 = INF; 30 for(int i = 0;i < n;i++){ 31 int x; 32 cin >> x; 33 if(x < Min1){ 34 Min1 = x; 35 } 36 } 37 for(int i = 0;i < m;i++){ 38 int x; 39 cin >> x; 40 if(x < Min2){ 41 Min2 = x; 42 } 43 } 44 cout << "Problem " << ++cnt << ":" << endl; 45 cout << "Shortest judge solution: " << Min1 << " bytes." << endl; 46 if(Min2 == INF) 47 cout << "Shortest team solution: N/A bytes." << endl; 48 else 49 cout << "Shortest team solution: " << Min2 << " bytes." << endl; 50 } 51 return 0; 52 }
SA-IS后缀数组
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <map> 7 #include <cmath> 8 #include <vector> 9 10 #define Faster ios::sync_with_stdio(false),cin.tie(0) 11 #define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) 12 #define Close fclose(stdin),fclose(stdout) 13 const int maxn = 1e4 + 5; 14 using namespace std; 15 const int MOD = 1e9+7; 16 typedef long long ll; 17 18 int main(){ 19 Faster; 20 int t; 21 cin >> t; 22 while(t--){ 23 int n; 24 cin >> n; 25 string s; 26 cin >> s; 27 int cnt = 0; 28 for(int i = 0;i < n-1;i++){ 29 if(s[i] == s[i+1]){ 30 cnt++; 31 } 32 else if(s[i] < s[i+1]){ 33 cnt++; 34 while(cnt){ 35 cnt--; 36 cout << "<"; 37 } 38 } 39 else if(s[i] > s[i+1]){ 40 cnt++; 41 while(cnt){ 42 cnt--; 43 cout << ">"; 44 } 45 } 46 } 47 while(cnt--){ 48 cout << ">"; 49 } 50 cout << endl; 51 } 52 return 0; 53 }