Last active
January 28, 2020 15:08
-
-
Save Chgtaxihe/3056e723c8e312749fe62e6a8c7d61e9 to your computer and use it in GitHub Desktop.
Codeforces 1263 #Codeforces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
#define F(i, n) for(int i=0; i<n; i++) | |
using namespace std; | |
void redirect_input() { freopen("./input.txt", "r", stdin); } | |
void redirect_output() { freopen("./output.txt", "w", stdout); } | |
const ll inf = 0x3f3f3f3f3f3f3f3f; | |
const int maxn = 2e5 + 100; | |
int val[3]; | |
void solve() { | |
int ans = 0; | |
F(i, 3) cin >> val[i]; | |
sort(val, val + 3, greater<int>()); | |
if(val[0] > val[1] + val[2]){ | |
ans = val[1] + val[2]; | |
}else{ | |
// 按最优策略,最后剩下的糖果数量为0或1 | |
ans = val[0] + val[1] + val[2]; | |
ans >>= 1; | |
} | |
cout << ans << '\n'; | |
} | |
signed main() { | |
Android; | |
int n; | |
cin >> n; | |
while(n--) | |
solve(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
#define F(i, n) for(int i=0; i<n; i++) | |
using namespace std; | |
void redirect_input() { freopen("./input.txt", "r", stdin); } | |
void redirect_output() { freopen("./output.txt", "w", stdout); } | |
const ll inf = 0x3f3f3f3f3f3f3f3f; | |
const int maxn = 2e5 + 100; | |
bool mark1[12], mark2[12]; | |
char code[12][6]; | |
void solve() { | |
F(i, 11) mark1[i] = mark2[i] = false; | |
int n, cnt=0; | |
cin >> n; | |
F(i, n) | |
cin >> code[i]; | |
F(i, n){ | |
if(mark1[i]) continue; | |
for(int j=i+1; j<n; j++){ | |
if(strcmp(code[i], code[j])==0) | |
mark1[j] = true; | |
} | |
mark2[code[i][0]-'0']=true; | |
} | |
F(i, n){ | |
if(!mark1[i]) continue; | |
cnt++; | |
F(j, 10){ | |
if(!mark2[j]){ | |
code[i][0] = j + '0'; | |
mark2[j]=true; | |
break; | |
} | |
} | |
} | |
cout << cnt << '\n'; | |
F(i, n){ | |
cout << code[i] << '\n'; | |
} | |
} | |
signed main() { | |
Android; | |
int n; | |
cin >> n; | |
while(n--) | |
solve(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
#define F(i, n) for(int i=0; i<n; i++) | |
using namespace std; | |
void redirect_input() { freopen("./input.txt", "r", stdin); } | |
void redirect_output() { freopen("./output.txt", "w", stdout); } | |
const ll inf = 0x3f3f3f3f3f3f3f3f; | |
const int maxn = 2e5 + 100; | |
vector<int> ans; | |
void solve() { | |
int n; | |
cin >> n; | |
ans.clear(); | |
int mx = n+1; | |
ans.push_back(0); | |
for(int i=1; i<mx; i++){ | |
int pa = n / i; | |
if(pa < i) break; | |
ans.push_back(i); | |
if(i != pa) ans.push_back(pa); | |
mx = pa; | |
} | |
sort(ans.begin(), ans.end()); | |
cout << ans.size() << '\n'; | |
for(int v:ans) cout << v << ' '; | |
cout << '\n'; | |
} | |
signed main() { | |
Android; | |
int n; | |
cin >> n; | |
while(n--) | |
solve(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
#define F(i, n) for(int i=0; i<n; i++) | |
using namespace std; | |
void redirect_input() { freopen("./input.txt", "r", stdin); } | |
void redirect_output() { freopen("./output.txt", "w", stdout); } | |
const ll inf = 0x3f3f3f3f3f3f3f3f; | |
const int maxn = 2e5 + 100; | |
set<int> keys[27]; | |
char buffer[100]; | |
int union_set[27]; | |
bool appear[27]; | |
int fa(int u){return union_set[u]==u?u:union_set[u]=fa(union_set[u]);} | |
void merge(int u, int v){ | |
u = fa(u), v = fa(v); | |
if(u != v) union_set[v] = u; | |
} | |
void solve() { | |
int n, len, ans=0; | |
cin >> n; | |
F(i, 26) union_set[i] = i, appear[i] = false; | |
F(i, n){ | |
cin >> buffer; | |
len = strlen(buffer); | |
appear[buffer[0]-'a'] = true; | |
for(int i=1; i<len; i++){ | |
appear[buffer[i]-'a'] = true; | |
merge(buffer[0]-'a', buffer[i]-'a'); | |
} | |
} | |
F(i, 26){ | |
if(appear[i] && union_set[i]==i) ans++; | |
} | |
cout << ans << '\n'; | |
} | |
signed main() { | |
Android; | |
solve(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
#define F(i, n) for(int i=0; i<n; i++) | |
using namespace std; | |
void redirect_input() { freopen("./input.txt", "r", stdin); } | |
void redirect_output() { freopen("./output.txt", "w", stdout); } | |
const ll inf = 0x3f3f3f3f3f3f3f3f; | |
const int maxn = 1e6 + 100; | |
stack<int> le, re, min_le, max_re; | |
int cnt_l = 0, cnt_r = 0; | |
char command[maxn]; | |
struct{ | |
stack<int> val; | |
stack<int> min_sum, max_sum; | |
int sum = 0; | |
void push(int v){ | |
val.push(v); | |
sum += v; | |
min_sum.push(min(sum, min_sum.empty()?sum:min_sum.top())); | |
max_sum.push(max(sum, max_sum.empty()?sum:max_sum.top())); | |
} | |
int pop(){ | |
int v = val.top(); | |
sum -= v; | |
val.pop(), min_sum.pop(), max_sum.pop(); | |
return v; | |
} | |
int top(){ | |
return val.top(); | |
} | |
}stk_l, stk_r; | |
void solve() { | |
int n, pos = 0; | |
cin >> n >> command; | |
F(i, n) stk_r.push(0); | |
stk_l.push(0); | |
F(i, n){ | |
char c = command[i]; | |
// cerr << "C: " << c << endl; | |
if(c == 'L'){ | |
if(pos > 0){ | |
pos--; | |
stk_r.push(stk_l.pop()); | |
} | |
}else if(c == 'R'){ | |
pos++; | |
stk_l.push(stk_r.pop()); | |
}else{ | |
stk_l.pop(); | |
if(c == '(') stk_l.push(1); | |
else if(c == ')') stk_l.push(-1); | |
else stk_l.push(0); | |
} | |
// 左侧没有 ")(",且右侧没有 ")(",且左右侧'('')'数量相等 | |
if(stk_l.min_sum.top()>=0 && stk_r.max_sum.top()<=0 && stk_l.sum+stk_r.sum==0){ | |
cout << max(stk_l.sum, max(stk_l.max_sum.top(), -stk_r.min_sum.top())) << " "; | |
}else{ | |
cout << "-1 "; | |
} | |
} | |
cout << '\n'; | |
} | |
signed main() { | |
Android; | |
solve(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment