diff --git a/volume007/714 - Copying Books(v2).cpp b/volume007/714 - Copying Books(v2).cpp new file mode 100644 index 00000000..6aec1789 --- /dev/null +++ b/volume007/714 - Copying Books(v2).cpp @@ -0,0 +1,56 @@ +#include +#include +using namespace std; + +const int maxn = 505; +long long num[maxn], sum[maxn]; +char idx[maxn],a[maxn]; +long long leftt,rightt,mid; +int m,k,n; + +inline bool binSearch(){ + long long val = 0; int cnt = 0; + memset(idx, 0, sizeof(idx)); + for(int i = m; i >= 1; --i){ + if(val+num[i] <= mid && i >= k-cnt) + val += num[i]; + else{ + cnt++; + val = num[i]; + idx[i] = 1; + } + } + if(cnt == k-1){ + memcpy(a, idx ,sizeof(idx)); + return true; + } + return false; +} + +int main(){ + ios::sync_with_stdio(false); + cin.tie(0); + + int cas; + cin >> cas; + while(cas--){ + rightt = leftt = 0; + cin >> m >> k; + for(int i = 1; i <= m; ++i){ + cin >> num[i]; + rightt += num[i]; + leftt = num[i]>leftt ? num[i]:leftt; + } + while(rightt >= leftt){ + mid = (leftt+rightt) >> 1; + if(binSearch()) rightt = mid -1; + else leftt = mid+1; + } + for(int i = 1; i < m; ++i){ + cout << num[i] << ' '; + if (a[i] == 1) cout << '/' << ' '; + } + cout << num[m] << '\n'; + } + return 0; +} diff --git a/volume014/1442 - Cav.cpp b/volume014/1442 - Cav.cpp new file mode 100644 index 00000000..cb8ed5b1 --- /dev/null +++ b/volume014/1442 - Cav.cpp @@ -0,0 +1,36 @@ +#include +#include +using namespace std; + +const int maxn = 1e6+5; +int cas, n, cnt; +int ceiling[maxn], floor[maxn]; + +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + //freopen("input.txt" , "r", stdin ); + //freopen("output.txt", "w", stdout); + cin >> cas; + while(cas--) { + cnt = 0; + cin >> n; + for (int i = 0; i < n; ++i) cin >> floor[i]; + for (int i = 0; i < n; ++i) cin >> ceiling[i]; + int tmp = maxn; + for (int i = 0; i < n; ++i) { + tmp = min(tmp, ceiling[i]); + tmp = max(tmp, floor[i]); + ceiling[i] = tmp; + } + tmp = maxn; + for (int i = n-1; i > -1; --i) { + tmp = min(tmp, ceiling[i]); + tmp = max(tmp, floor[i]); + ceiling[i] = tmp; + cnt += ceiling[i] - floor[i]; + } + cout << cnt << '\n'; + } + return 0; +} diff --git a/volume014/1451 - Average(v2).cpp b/volume014/1451 - Average(v2).cpp new file mode 100644 index 00000000..ae2dfb58 --- /dev/null +++ b/volume014/1451 - Average(v2).cpp @@ -0,0 +1,51 @@ +#include +#include +using namespace std; + +const int maxn = 100005; +int n, L, start, ending,temp; +double maxd; +int DNA[maxn],cav[maxn]; +string str; + +inline int cntAverage(int L, int r, int LL, int rr, int DNA[]){ + return (DNA[r]-DNA[L])*(rr-LL) - (DNA[rr]-DNA[LL])*(r-L); +} + +inline void changePoint(int pits,int bump){ + double temp; + temp = cntAverage(pits, bump, start-1, ending, DNA); + if (temp < 0) return; + if (temp || (bump-pits) < (ending-start+1)){ + maxd = temp; + start = pits + 1; + ending = bump; + } +} + +int main(){ + ios::sync_with_stdio(false); + cin.tie(0); + + int cas; + cin >> cas; + while (cas--){ + int find = 0, cor = -1; + cin >> n >> L; cin.get(); + getline(cin, str); + for (int i = 1; i <= n; ++i) + DNA[i] = DNA[i-1] + (str[i-1] == '1'); + maxd = DNA[L] / L, start = 1, ending = L; + for (int i = L; i <= n; ++i){ + temp = i - L; + while (find < cor && cntAverage(cav[cor], temp, cav[cor - 1], cav[cor], DNA) <= 0) + --cor; + cav[++cor] = temp; + while (find < cor && cntAverage(cav[find], i, cav[find + 1], i, DNA) <= 0) + ++find; + changePoint(cav[find],i); + } + cout << start << ' ' << ending << '\n'; + } + return 0; +} diff --git a/volume014/1471 - Defense Lines.cpp b/volume014/1471 - Defense Lines.cpp new file mode 100644 index 00000000..cf0f0e18 --- /dev/null +++ b/volume014/1471 - Defense Lines.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +using namespace std; + +const int maxn = 2*1e5+1; +int n,ans; +int a[maxn],g[maxn],f[maxn],bin[maxn]; +int main(){ + ios::sync_with_stdio(false); + cin.tie(0); + + int cas; + cin >> cas; + while (cas--){ + cin >> n; + for (int i = 1; i <= n; ++i){ + cin >> a[i]; + if (a[i]>a[i - 1]) + g[i] = g[i - 1] + 1; + else g[i] = 1; + } + a[n + 1] = 0; + for (int i = n; i > 0; --i){ + if (a[i] < a[i + 1]) + f[i] = f[i + 1] + 1; + else f[i] = 1; + } + + ans = 0; + memset(bin, 0x7f, sizeof(bin)); + bin[0] = -1; + for (int i = 1; i <= n; ++i){ + ans = max(ans, int(f[i]+lower_bound(bin, bin+n, a[i])-bin-1)); + bin[g[i]] = min(bin[g[i]], a[i]); + } + + cout << ans << '\n'; + } + return 0; +} diff --git a/volume016/1606 - Amphiphilic Carbon Molecules.cpp b/volume016/1606 - Amphiphilic Carbon Molecules.cpp new file mode 100644 index 00000000..698d5c97 --- /dev/null +++ b/volume016/1606 - Amphiphilic Carbon Molecules.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +using namespace std; + +const int N=1001; + +class Point{ +public: + int x,y,color; + double rad; + bool operator<(const Point &rhs)const{ + return rad=0; +} + +int main(){ + ios::sync_with_stdio(false); + cin.tie(0); + + while(cin>>n && n){ + for(int i=0;i<(n);i++) + cin >> dot[i].x >> dot[i].y >> dot[i].color; + if(n<=2) return 2; + int ans=0; + + for(int i=0;i= num) scani = scani-num; + cnt++; + } + while(scani!=divi && isInArea(tempDot[divi],tempDot[scani])){ + scani=scani+1; + if(scani >= num) scani = scani-num; + cnt++; + } + cnt--; + divi++; + ans=max(ans,cnt); + } + } + cout << ans << '\n'; + } + return 0; +} diff --git a/volume016/1607 - Gates.cpp b/volume016/1607 - Gates.cpp new file mode 100644 index 00000000..78d829e7 --- /dev/null +++ b/volume016/1607 - Gates.cpp @@ -0,0 +1,50 @@ +#include +using namespace std; + +#define LL gate[i].in1 +#define RR gate[i].in2 + +class gateClass { +public: + int in1, in2, out; +} gate[200005]; +int n, m, all0, all1; + +int getOutput(int pos) { + for (int i = 1; i <= m; i++) { + int x = LL>0 ? gate[LL].out:-LL<=pos; + int y = RR>0 ? gate[RR].out:-RR<=pos; + gate[i].out = !(x && y); + } + return gate[m].out; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + + int cas , mid; + cin >> cas; + while (cas--) { + cin >> n >> m; + for (int i = 1; i <= m; i++) + cin >> gate[i].in1 >> gate[i].in2; + int all0 = getOutput(0); + int all1 = getOutput(n); + if (all0 == all1) { + for (int i = 1; i <= n; i++) cout << '0'; + } else { + int lef = 1, rit = n; + while (lef < rit) { + mid = lef + rit >> 1; + if (getOutput(mid) == all1) rit = mid; + else lef = mid + 1; + } + for (int i = 1; i < rit; i++) cout << '1'; + cout << 'x'; + for (int i = rit + 1; i <= n; i++) cout << '0'; + } + cout << '\n'; + } + return 0; +} diff --git a/volume016/1609 - Foul Play.cpp b/volume016/1609 - Foul Play.cpp new file mode 100644 index 00000000..08602c88 --- /dev/null +++ b/volume016/1609 - Foul Play.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +using namespace std; + +const int maxn = 1025; +char team[maxn][maxn]; +int n; +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + //freopen("input.txt" , "r", stdin ); + //freopen("output.txt", "w", stdout); + while(cin >> n){ + for(int i = 1; i <= n; ++i) { + cin >> team[i]+1; + } + vector win, lose; + for(int i = 2; i <= n; ++i) { + if(team[1][i] == '1') + win.push_back(i); + else lose.push_back(i); + } + int leftTeam = n; + while (leftTeam > 1) { + vector winSub, loseSub, round3; + for(int i = 0; i < lose.size(); ++i) { + bool matched = false; + for(int j = 0; j < win.size(); ++j){ + if(win[j] && team[win[j]][lose[i]] == '1'){ + cout << win[j] << ' ' <>= 1; + } + } + return 0; +} + diff --git a/volume115/11572 - Unique Snowflakes(v2).cpp b/volume115/11572 - Unique Snowflakes(v2).cpp new file mode 100644 index 00000000..42858a1f --- /dev/null +++ b/volume115/11572 - Unique Snowflakes(v2).cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include +using namespace std; + +int snowflakes[1000000+1]; +int idx[1000000 + 1]; +int n; +int main(){ + ios::sync_with_stdio(false); + cin.tie(0); + + int cas; + cin >> cas; + while (cas--){ + int maxSnow = 0; + int l = 0, r = 0; + memset(idx, 0, sizeof(idx)); + cin >> n; + for (int i = 0; i < n; ++i){ + cin >> snowflakes[i]; + } + + while (r < n){ + while (r < n && !idx[snowflakes[r]]) + idx[snowflakes[r++]] = 1; + maxSnow = max(maxSnow, r - l); + idx[snowflakes[l++]] = 0; + } + cout << maxSnow << '\n'; + } + return 0; +} diff --git a/volume115/11572 - Unique Snowflakes.cpp b/volume115/11572 - Unique Snowflakes.cpp new file mode 100644 index 00000000..4ed180c7 --- /dev/null +++ b/volume115/11572 - Unique Snowflakes.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +using namespace std; + +const int maxn = 1000001; +int snowflakes[maxn]; +int n; +set snow; +int main(){ + ios::sync_with_stdio(false); + cin.tie(0); + + int cas; + cin >> cas; + while (cas--){ + int maxSnow = 0; + int l = 0, r = 0; + snow.clear(); + cin >> n; + for (int i = 0; i < n; ++i){ + cin >> snowflakes[i]; + } + + while (r < n){ + while (r < n && !snow.count(snowflakes[r])) + snow.insert(snowflakes[r++]); + maxSnow = max(maxSnow, r - l); + snow.erase(snowflakes[l++]); + } + cout << maxSnow << '\n'; + } + return 0; +} diff --git a/volume126/12627 - Erratic Expansion.cpp b/volume126/12627 - Erratic Expansion.cpp new file mode 100644 index 00000000..979fdd9a --- /dev/null +++ b/volume126/12627 - Erratic Expansion.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +long long k, a, b, tot; +long long idx[31] = {1}; + +long long solve(long long k, long long i){ + if (!i) return 0; + if (!k) return 1; + if (i > (1LL << k-1)) + return (solve(k-1, i-(1LL << k-1)) + 2 * idx[k-1]); + return 2 * solve(k-1, i); +} + +int main(){ + ios::sync_with_stdio(false); + cin.tie(0); + + int cas, n = 0; + cin >> cas; + for (int i = 1; i < 30; ++i) + idx[i] = 3 * idx[i-1]; + while (++n <= cas){ + cin >> k >> a >> b; + tot = solve(k, b) - solve(k, a-1); + cout << "Case " << n << ": "<< tot << '\n'; + } + return 0; +}