2021年度训练联盟热身训练赛第三场
A.Circuit Math
题意:给定你n个真值分别表示A-Z,规定+为|,-为!,*为&,T为真,F为假。求最后的真值。
思路:直接模拟。
代码:

1 #include<iostream> 2 #include<algorithm> 3 #include<cmath> 4 #include<cstring> 5 #include<cstdio> 6 int maxx=1e5+10; 7 using namespace std; 8 int main(){ 9 int n; 10 scanf("%d",&n); 11 int c[maxx]; 12 int op[maxx]; 13 for(int i = 1 ; i <= n ; i++){ 14 string c; 15 cin >> c; 16 if(c[0]=='T') 17 op[i] = 1; 18 else op[i] = 0; 19 } 20 string s; 21 getchar(); 22 getline(cin, s); 23 int st[maxx]={0}; 24 int top=0; 25 for(int i = 0 ; i < s.size() ; i++) 26 { 27 if(s[i] == ' ') continue; 28 29 if(s[i] >= 'A' && s[i] <= 'Z') 30 { 31 st[++top] = op[s[i] - 'A' + 1] ; 32 } 33 else if(s[i] != '-') 34 { 35 int t1 = st[top]; 36 top--; 37 int t2 = st[top]; 38 top--; 39 if(s[i] == '+') 40 { 41 int t = (t1 | t2); 42 st[++top] = t; 43 44 } 45 else 46 { 47 int t = (t1 & t2); 48 st[++top] = t; 49 } 50 51 } 52 else 53 { 54 int t1 = st[top]; 55 top--; 56 st[++top] = (!t1); 57 } 58 59 } 60 if(st[top] == 1) puts("T"); 61 else puts("F"); 62 }
B.Diagonal Cut
题意:给你一个nm的矩阵让你让你求一共多少个对角线将一个11的正方形分成面积相等的两份。
思路:找规律如果n==m那么一定是n个.如果n和m互质,若n和m都是奇数他中间那个一定是平分的其他的不能平分,所以是1.互质有一个或者都不是奇数那么一个都不平分.就是0。剩下的就死和不互质,那我们转化整他们互质的情况乘以gcd即可,转换成互质的即除以gcd再取判断奇偶性,有偶数那么即使有gcd也是0,都是奇数,就直接输出gcd即可。
代码:

1 #include <stack> 2 #include <set> 3 #include <map> 4 #include <queue> 5 #include <string> 6 #include <iostream> 7 #include <stdio.h> 8 #include <string.h> 9 #include <algorithm> 10 #include <math.h> 11 using namespace std; 12 const int MOD = 10007; 13 const int mod = 998244353; 14 const int maxn = 2e5 + 1010; 15 const int dx[] = {1, 1, 1, 0, 0, -1, -1, -1}; 16 const int dy[] = {1, 0, -1, -1, 1, -1, 1, 0}; 17 long long a[26], b[maxn], c[maxn]; 18 long long ans, n, m, len, k; 19 string str; 20 long long dp[maxn][50]; 21 stack<int>s; 22 void solve(){ 23 cin >> n >> m; 24 if(n == m){ 25 cout << n << endl; 26 return ; 27 } 28 long long ans = __gcd(n, m); 29 if(ans == 1 && n % 2 && m % 2){ 30 cout << 1 << endl; 31 }else if(ans == 1){ 32 cout << 0 << endl; 33 }else{ 34 if((n / ans) % 2 && (m / ans) % 2) cout << ans << endl; 35 else cout << 0 << endl; 36 } 37 } 38 int main(){ 39 solve(); 40 return 0; 41 }
D.Missing Numbers
题意:输出缺少的数字
思路:直接输出查找即可
代码:

1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cmath> 5 #include<cstring> 6 #include<stack> 7 #include<queue> 8 #include<vector> 9 using namespace std; 10 int main(){ 11 int n; 12 scanf("%d",&n); 13 int a[n+1]; 14 int flag=1; 15 int sum=0; 16 for(int i=0;i<n;i++){ 17 scanf("%d",&a[i]); 18 } 19 int i=0; 20 while(flag!=a[n-1]){ 21 if(flag==a[i]){ 22 flag++; 23 i++; 24 continue; 25 }else{ 26 printf("%d\n",flag); 27 flag++; 28 sum++; 29 } 30 } 31 if(sum==0){ 32 printf("good job"); 33 } 34 }
K.Summer Trip
题意:就是给出以一个只含’a’-'z’的序列,然后让你选长度至少为2的第一字符没有重复,最后一个字符也没有重复的子序列。
思路:直接枚举暴力
代码:

1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int p[30]; 5 set<int> st[30]; 6 int main() 7 { 8 string s; 9 cin>>s; 10 ll ans=0; 11 for(int i=0;i<s.size();i++) 12 { 13 int x=s[i]-'a'+1; 14 ans+=st[x].size(); 15 for(int j=1;j<=26;j++) 16 st[j].insert(x); 17 st[x].clear(); 18 } 19 cout<<ans<<endl; 20 return 0; 21 }
M。Zipline
题意:给出两个杆长,给出你两个杆的距离,给出你最低点的高度,求绳最短和绳最长
思路:当时没有思路,看了看学了学,才知道:
最低点受力平衡,所以左三角与右三角相似,底边长度比等于杆长度比(较最低点比).这就求出水平长度,勾股定理求出两个边长度和,即可.
注意:有种可能就是,最低点与一杆高相等,相对高度就是0,可以直接写两杆最高点的距离(最长和最短相等)
代码:(觉得有些神奇)

1 #include <stack> 2 #include <set> 3 #include <map> 4 #include <queue> 5 #include <string> 6 #include <iostream> 7 #include <stdio.h> 8 #include <string.h> 9 #include <algorithm> 10 #include <math.h> 11 using namespace std; 12 typedef long long ll; 13 typedef pair<ll, ll> pii; 14 typedef unsigned long long ull; 15 16 #define x first 17 #define y second 18 #define sf scanf 19 #define pf printf 20 #define inf 0x3f3f3f3f 21 #define mem(a,x) memset(a,x,sizeof(a)) 22 #define rep(i,n) for(int i=0;i<(n);++i) 23 #define repi(i,a,b) for(int i=int(a);i<=(b);++i) 24 #define repr(i,b,a) for(int i=int(b);i>=(a);--i) 25 #define debug(x) cout << #x << ": " << x << endl; 26 27 const int MOD = 10007; 28 const int mod = 998244353; 29 const int maxn = 2e5 + 1010; 30 const int dx[] = {1, 1, 1, 0, 0, -1, -1, -1}; 31 const int dy[] = {1, 0, -1, -1, 1, -1, 1, 0}; 32 33 34 void solve() 35 { 36 double w, g, h, r; 37 cin >> w >> g >> h >> r; 38 double a1 = g - r, a2 = h - r; 39 if(a1==0&&a2==0){ 40 printf("%.8lf %.8lf\n", w, w); 41 return; 42 } 43 else if(a1==0){ 44 printf("%.8lf %.8lf\n", sqrt(w*w+a2*a2), sqrt(w*w+a2*a2)); 45 return ; 46 }else if(a2==0){ 47 printf("%.8lf %.8lf\n", sqrt(w*w+a1*a1), sqrt(w*w+a1*a1)); 48 return ; 49 } 50 double b1 = double(w * (a1 *1.0/ (a1 + a2))); 51 double b2 = w - b1; 52 53 double maxx = sqrt(b1 * b1 + a1 * a1) + sqrt(a2 * a2 + b2 * b2); 54 double minn = sqrt(fabs(g - h) * fabs(g - h) + w * w); 55 printf("%.8lf %.8lf\n", minn, maxx); 56 } 57 58 int main() 59 { 60 ll t; 61 cin>>t; 62 while(t--) 63 { 64 solve(); 65 } 66 return 0; 67 }