Skip to content

Commit da1f09b

Browse files
committed
update P2602.md
1 parent 59e1bca commit da1f09b

File tree

5 files changed

+165
-2
lines changed

5 files changed

+165
-2
lines changed

acwing/46.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
### T1
2+
> 贪心
3+
```c++
4+
void solve(){
5+
int a, b, c, d;
6+
cin >> a >> b >> c >> d;
7+
if(b < a) cout << "First\n";
8+
else cout << "Second\n";
9+
}
10+
11+
```
12+
13+
### T2
14+
> 贪心,排序
15+
思考切换后得到效益最高,必定出现在背面值减去正面值最大的情况下
16+
```c++
17+
void solve(){
18+
int n, m; cin >> n >> m;
19+
vector <pii> a(n);
20+
for(int i = 0; i < n; i++) cin >> a[i].fi;
21+
for(int i = 0; i < n; i++) cin >> a[i].se;
22+
sort(begin(a), end(a), [&](const auto & a, const auto & b){
23+
return a.fi - a.se > b.fi - b.se;
24+
});
25+
m = n - m;
26+
int ans = 0;
27+
for(int i = 0; i < n; i++){
28+
if(m > 0 && a[i].fi - a[i].se > 0) ans += a[i].se, m--;
29+
else ans += a[i].fi;
30+
}
31+
cout << ans << endl;
32+
33+
}
34+
```
35+
36+
### T3
37+
> 预处理
38+
39+
```c++
40+
#include <bits/stdc++.h>
41+
using namespace std;
42+
43+
using pii = pair<int,int>;
44+
using ll = long long;
45+
using ull = unsigned long long;
46+
using piii = pair<int, pii>;
47+
48+
void dbg(){puts("");}
49+
template<typename T, typename... R>void dbg(const T &f, const R &... r) {
50+
cout << f << " ";
51+
dbg(r...);
52+
}
53+
#define pb push_back
54+
#define ep emplace_back
55+
#define all(x) (x).begin(),(x).end()
56+
#define fi first
57+
#define se second
58+
#define mp make_pair
59+
#define all(x) x.begin(), x.end()
60+
#define endl "\n"
61+
62+
template <typename T> void chkmax(T &x, T y) { if (y > x) x = y; }
63+
template <typename T> void chkmin(T &x, T y) { if (y < x) x = y; }
64+
65+
66+
void solve(){
67+
int n, q;
68+
cin >> n;
69+
string s;
70+
unordered_map <string, int> cnt;
71+
unordered_map <string, string> pstr;
72+
unordered_set <string> S;
73+
for(int i = 0; i < n; i++){
74+
cin >> s;
75+
S.clear();
76+
for(int i = 1; i <= s.size(); i++){
77+
for(int j = 0; j + i <= s.size(); j++){
78+
S.insert(s.substr(j, i));
79+
}
80+
}
81+
for(auto & str: S) {
82+
cnt[str]++;
83+
if(!pstr.count(str)) pstr[str] = s;
84+
}
85+
}
86+
cin >> q;
87+
while(q--){
88+
cin >> s;
89+
cout << cnt[s] << ' ';
90+
if(cnt[s]) cout << pstr[s] << endl;
91+
else cout << '-' << endl;
92+
}
93+
}
94+
95+
96+
int main(){
97+
ios_base::sync_with_stdio(0);
98+
cin.tie(0);
99+
int t = 1;
100+
while(t--){
101+
solve();
102+
}
103+
return 0;
104+
}
105+
106+
107+
108+
109+
```

codeforces/779/codeforces779 div2.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,3 @@ void solve(){
118118
cout << ans << endl;
119119
}
120120
```
121-
122-
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# codeforces 1630A
2+
3+
> 这是一道分类细节稍多的构造,我参考了scott的一种比较优秀的作法,按照他的构造,能把分类情况减少很多
4+
5+
首先是无解的情况:
6+
7+
- 当且仅当n = 4, k = 3的时候,用枚举的方法容易发现这是无法构造出来的
8+
9+
接着思考,在什么情况下可能会出现无解?
10+
11+

codeforces/constructive_algorithms/1646C.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,11 @@ int main(){
4747
return 0;
4848
}
4949
```
50+
51+
52+
53+
54+
55+
56+
57+
###
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# codeforces contest748 C
2+
3+
> 按tag是constructive problems,但是实际上感觉是greedy的
4+
5+
首先需要明确一点,最少的点依赖于这些走的距离一定是最长的线段,就是说,我不是到处设点,如何判断是否当前点一定是需要设点的呢?需要厘清一下过程:
6+
7+
**当出现往回走的情况的时候,如果说我们走着走着往回走了,这就说明,之前方向的最远处一定是需要走的点,我们走完了往回走寻找下一个点**
8+
9+
```cpp
10+
int main(){
11+
ios_base::sync_with_stdio(0);
12+
cin.tie(0);
13+
//greedy: makes points as least as possible
14+
//line as long as possible
15+
string s;
16+
int n;
17+
cin >> n >> s;
18+
unordered_set <int> S;
19+
int ans = 0;
20+
for(char & c: s){
21+
if(c == 'L') c = -1;
22+
if(c == 'R') c = 1;
23+
if(c == 'U') c = -2;
24+
if(c == 'D') c = 2;
25+
}
26+
for(int i = 0; i < n; i++){
27+
if(S.count(s[i])) continue;
28+
if(S.count(-s[i])) { //当出现了往回走的情况,这说明我们当前深入的点是需要走的,否则不需要如此“大费周章”
29+
S.clear();
30+
ans++;
31+
}
32+
S.insert(s[i]);
33+
}
34+
cout << ans + 1 << endl;
35+
return 0;
36+
}
37+
```

0 commit comments

Comments
 (0)