2020劳动节天天乐(4)题解
A - 两只脑斧
题意:给你n个字符串,根据图判断呼还是吸还是停顿
思路:模拟,细心发现,偶数和7的时候是吸,0是停顿,其余是呼。
代码
1 #include<iostream> 2 #include<algorithm> 3 #include<vector> 4 #include<map> 5 #include<stack> 6 #include<cstring> 7 #include<cmath> 8 using namespace std; 9 #define ll long long 10 #define double long double 11 #define eps 0.0000000001//偏差值1e8 12 const int N = 2e5 + 5; 13 const int mod = 1e9 + 9; 14 ll a[N],dp[N][2];//0为正,1为负 15 int main() 16 { 17 ll i, j, k; 18 ll n, m, t; 19 ll count1 = 0, count2 = 0; 20 cin >> t; 21 while (t--) 22 { 23 string s; 24 cin >> s; 25 if (s[0] - '0' == 0) 26 cout << "X"; 27 else if (s[0] - '0' == 7) 28 cout << "I"; 29 else if ((s[0] - '0') % 2 == 0) 30 cout << "I"; 31 else 32 cout << "E"; 33 } 34 35 }
C - 赛尔逵传说
题意:零氪有k点攻击力,c个“力量炖水果”(吃一个加k点攻击,可多次吃),给你n个怪di血xi攻击,问零氪最少承受攻击力。
思路:贪心,零氪打死一只怪要(d/k)-1次,而力量水果c其实实际上是 减少零氪打死怪的攻击次数,怎样减最好呢?当然减去攻击力最高,先排除零氪能一下秒的怪,再排序即可
代码
1 #include<iostream> 2 #include<algorithm> 3 #include<vector> 4 #include<map> 5 #include<stack> 6 #include<cstring> 7 #include<cmath> 8 using namespace std; 9 #define ll long long 10 #define double long double 11 #define eps 0.0000000001//偏差值1e8 12 const int N = 2e5 + 5; 13 const int mod = 1e9 + 9; 14 const int MOD = 998244353; 15 struct node { 16 ll d, x; 17 }a[N]; 18 bool cmp(const node& a, const node& b) 19 { 20 if (a.x == b.x)return a.d < b.d; 21 else 22 return a.x > b.x; 23 } 24 int main() 25 { 26 ll i, j, k; 27 ll n, m, t,c; 28 ll ret = 0, count1 = 0, count2 = 0; 29 cin >> n >> k>>c; 30 for (i = 1; i <= n; i++) 31 { 32 ll d, x; 33 cin >> d >> x; 34 if (d > k) 35 { 36 a[ret].d = d, a[ret].x = x; 37 ret++; 38 } 39 } 40 sort(a, a + ret, cmp); 41 ll count = 0;//共计次数 42 ll ans = 0;//受伤量 43 for (i = 0; i < ret; i++) 44 { 45 if (a[i].d % k != 0) 46 count = a[i].d / k; 47 else 48 count = a[i].d / k - 1; 49 if (c != 0)//优先慢慢用完 50 { 51 if (count > c) 52 { 53 count -= c; 54 c = 0; 55 } 56 else 57 { 58 c -= count; 59 count = 0; 60 } 61 } 62 ans += count * a[i].x; 63 } 64 cout << ans << endl; 65 66 }
D - 只有一端开口的瓶子
题意:给你一个一个乱序的全排列,可以有k个栈存入,有push,pop,move操作,要使序列变成递增序列,问最小k是多少
思路:其实仔细想想你最多只需要俩个栈就可以,跟汉诺塔的原理差不多的,因为是全排列,你可以拿一个栈模拟能否成功,能就一个,不能就两个
呈上代码
1 #include<iostream> 2 #include<algorithm> 3 #include<vector> 4 #include<map> 5 #include<stack> 6 #include<cstring> 7 #include<cmath> 8 using namespace std; 9 #define ll long long 10 #define double long double 11 #define eps 0.0000000001//偏差值1e8 12 const int N = 2e5 + 5; 13 const int mod = 1e9 + 9; 14 const int MOD = 998244353; 15 ll a[N]; 16 stack<ll>b; 17 int main() 18 { 19 ll i, j, k; 20 ll n, m, t,c; 21 cin >> t; 22 while (t--) 23 { 24 while (!b.empty()) 25 b.pop(); 26 cin >> n; 27 for (i = 1; i <= n; i++) 28 cin >> a[i]; 29 ll pos = 1;//找到pos就可以直接pop出来 30 for (i = 1; i <= n; i++)// 31 { 32 b.push(a[i]); 33 while (!b.empty()&&b.top() == pos) 34 { 35 pos++; 36 b.pop(); 37 } 38 } 39 if (b.empty()) 40 cout << 1 << endl; 41 else 42 cout << 2 << endl; 43 } 44 45 }
E - 风王之瞳
题意:给N*M的网格,问你能有多少个正方形
思路:纯属规律题,也有dp的做法,就不详细介绍dp做法了。
我在其他地方找到的,懒得画了
代码
1 #include<iostream> 2 #include<algorithm> 3 #include<vector> 4 #include<map> 5 #include<stack> 6 #include<cstring> 7 #include<cmath> 8 using namespace std; 9 #define ll long long 10 #define double long double 11 #define eps 0.0000000001//偏差值1e8 12 const int N = 2e5 + 5; 13 const int mod = 1e9 + 9; 14 ll a[N],dp[N][2];//0为正,1为负 15 int main() 16 { 17 ll i, j, k; 18 ll n, m, t; 19 ll count1 = 0, count2 = 0; 20 cin >> t; 21 while (t--) 22 { 23 cin >> n >> m; 24 ll sum = 0; 25 for (i = 1; i <= min(n, m); i++) 26 sum += (m - i + 1) * (n - i + 1)*i; 27 cout << sum << endl; 28 } 29 30 }
G - 目标是成为数论大师
题意:函数f(x)=√ax+b,问你f(x)=x有多少个点,并输出坐标
思路:把 f(x)=x代入得x^2-(2*b+a)*x+b^2=0,求解二元一次方程根就好,注意要排除增根
代码
1 #include<iostream> 2 #include<algorithm> 3 #include<vector> 4 #include<map> 5 #include<stack> 6 #include<cstring> 7 #include<cmath> 8 using namespace std; 9 #define ll long long 10 #define double long double 11 #define eps 0.0000000001//偏差值1e8 12 const int N = 2e5 + 5; 13 const int mod = 1e9 + 9; 14 int main() 15 { 16 ll i, j, k; 17 ll n, m, t; 18 ll count1 = 0, count2 = 0; 19 cin >> t; 20 while (t--) 21 { 22 ll a, b; 23 ll x1, x2; 24 cin >> a >> b; 25 ll delta = 4 * a * b + a * a; 26 if (delta > 0)//两个点 27 { 28 29 x1 = ((2 * b + a) + sqrt(delta))/2; 30 x2 =( (2 * b + a) - sqrt(delta)) / 2 ; 31 ll flag1 = 0, flag2 = 0; 32 //去增根 33 if (sqrt(a * x1) + b == x1) 34 flag1 = 1; 35 if (sqrt(a * x2) + b == x2) 36 flag2 = 1; 37 if(flag1&&flag2) 38 { 39 cout << 2 << endl; 40 cout << x2 << " " << x1 << endl; 41 } 42 else 43 { 44 cout << 1 << endl; 45 if (flag1) 46 cout << x1 << endl; 47 else 48 cout << x2 << endl; 49 } 50 } 51 else 52 { 53 cout << 1 << endl; 54 cout << (2 * b + a)/2 << endl; 55 } 56 } 57 58 }
H - 金色传说
题意:在计算机必输入n位,可输0-9 + -十二个键,但要符合计算式要求,输够n位后自动生成解,问所有解的和是多少
思路:没什么思路,靠的数学感觉加上计算器的辅助,网上有dp的做法
代码
1 #include<iostream> 2 #include<algorithm> 3 #include<vector> 4 #include<map> 5 #include<stack> 6 #include<cstring> 7 #include<cmath> 8 using namespace std; 9 #define ll long long 10 #define double long double 11 const int N = 5e5 + 5; 12 const int mod = 1e9 + 9; 13 const int MOD = 998244353; 14 ll a[N]; 15 ll fastPow(ll a, ll n) 16 { 17 ll base = a%MOD; 18 ll res = 1; 19 while (n) 20 { 21 if (n & 1) 22 res = (res*base)%MOD; 23 base = (base*base)%MOD; 24 n >>= 1; 25 } 26 return res % MOD; 27 } 28 int main() 29 { 30 ll i, j, k; 31 ll n, m, t,c; 32 a[1] = 45, a[2] = 4950; 33 ll sum = 0; 34 for (i = 3; i <=500001; i++) 35 { 36 ll x = fastPow(10, i); 37 sum =( sum + a[i - 2] * 20)%MOD; 38 a[i] = ((x * (x - 1) / 2)%MOD + sum)%MOD; 39 sum = (sum*10)%MOD; 40 } 41 cin >> t; 42 while (t--) 43 { 44 cin >> n; 45 //cout << "TEXT:"; 46 //ll x = fastPow(10, n); 47 //cout << x * (x-1) / 2 << endl; 48 cout << a[n]%MOD << endl; 49 } 50 51 }
I - 多项式求导
题意:给你最高n次项多项式,求k次求导后n次项各个系数
思路:根据求导方式来求,求到的结果再把原来数组更新就好,数据不大
代码
1 #include<iostream> 2 #include<algorithm> 3 #include<vector> 4 #include<map> 5 #include<stack> 6 #include<cstring> 7 #include<cmath> 8 using namespace std; 9 #define ll long long 10 #define double long double 11 #define eps 0.0000000001//偏差值1e8 12 const int N = 2e5 + 5; 13 const int mod = 1e9 + 9; 14 const int MOD = 998244353; 15 ll a[N]; 16 ll b[N]; 17 int main() 18 { 19 ll i, j, k; 20 ll n, m, t; 21 ll count1 = 0, count2 = 0; 22 cin >> n >> k; 23 for (i = 0; i <= n; i++) 24 cin >> a[i]; 25 b[0] = 0; 26 for (j = 0; j < k; j++) 27 { 28 for (i = 0; i < n; i++) 29 { 30 b[i + 1] = (n - i) * a[i]%MOD; 31 } 32 for (i = 0; i <= n; i++) 33 a[i] = b[i]; 34 } 35 for (i = 0; i <= n; i++) 36 cout << b[i] << " "; 37 38 }