abc370 A-E題解 (AtCoder Beginner Contest 370)

congmingyige發表於2024-09-07

A

這類簡單題,看清楚:

Output

Print Yes, No, or Invalid according to the instructions in the problem statement.

B

C

std,這樣寫(0->n-1,n-1->0),可以少寫一個vector

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main() {
 5     string s, t;
 6     cin >> s >> t;
 7     vector<string> ans;
 8     vector<int> v;
 9     int n = s.size();
10     for (int i = 0; i < n; i++) {
11         if (s[i] > t[i]) v.push_back(i);
12     }
13     for (int i = n - 1; i >= 0; i--) {
14         if (s[i] < t[i]) v.push_back(i);
15     }
16     int sz = v.size();
17     for (int i = 0; i < sz; i++) {
18         s[v[i]] = t[v[i]];
19         ans.push_back(s);
20     }
21     cout << sz << '\n';
22     for (string e : ans) cout << e << '\n';
23 }

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define LL long long
 4 #define ULL unsigned long long
 5 
 6 const LL mod_1=1e9+7;
 7 const LL mod_2=998244353;
 8 
 9 const double eps_1=1e-5;
10 const double eps_2=1e-10;
11 
12 const int maxn=2e5+10;
13 
14 vector<int> v1,v2;
15 
16 int main()
17 {
18     int i,cnt=0;
19     string s1,s2;
20     cin>>s1>>s2;
21     for (i=0;i<s1.size();i++)
22         if (s1[i]>s2[i])
23             v1.emplace_back(i), cnt++;
24         else if (s1[i]<s2[i])
25             v2.emplace_back(i), cnt++;
26     cout<<cnt<<endl;
27     for (auto d:v1)
28     {
29         s1[d] = s2[d];
30         cout<<s1<<endl;
31     }
32     reverse(v2.begin(),v2.end());
33     for (auto d:v2)
34     {
35         s1[d] = s2[d];
36         cout<<s1<<endl;
37     }
38 
39     return 0;
40 }

D

E

就是要找出前面

如果暴力做,

特殊情況,全部0 0 0 ; -1 1 -1 1 這樣的

好短程式碼,很快能寫完。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define LL long long
 4 #define ULL unsigned long long
 5 
 6 const LL mod=998244353;
 7 
 8 const double eps_1=1e-5;
 9 const double eps_2=1e-10;
10 
11 const int maxn=2e5+10;
12 
13 map<LL, LL> mp;
14 
15 int main()
16 {
17     LL n,k,a,i,ans=0,sum=0, exc_ans, exc_sum;
18     mp[0]=1;
19     sum=1;
20     cin>>n>>k;
21     for (i=1;i<=n;i++)
22     {
23         cin>>a;
24         ans+=a;
25 
26         exc_ans = ans-k;
27 
28         if (mp.find(exc_ans)!=mp.end())
29             exc_sum = (sum - mp[exc_ans] + mod) % mod;
30         else
31             exc_sum = sum;
32 
33         mp[ans] = (mp[ans] + exc_sum) % mod;
34         sum = (sum + exc_sum) % mod;
35 
36         if (i==n)
37             cout << (exc_sum % mod + mod) % mod;
38     }
39 
40     return 0;
41 }

F

G

相關文章