cf1562 C. Rings
生活随笔
收集整理的這篇文章主要介紹了
cf1562 C. Rings
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
cf1562 C. Rings
題意:
給你一個長度為n的01串,在01串選兩個連續區間S和T,要求區間長度>=?n2?\lfloor \frac{n}{2} \rfloor?2n??。
現在定義一個函數f(S):將S01串以2二進制轉化成10進制,要求f(S)是f(T)的倍數
題解:
構造題
我們思考有0的情況,如果0出現在左半部分(第pos位),那我們可以構造第pos位到第n位,第pos+1位到第n位。相當于這兩串的十進制是一樣的,只是前者多了一個前綴0
如果0出現在右半部分(第pos位),如果一個數右移一位,就是去掉末尾0,相當于除2,就是構造第1位到第pos位,第1位到第pos-1位
如果沒有0全是1就更好構造,直接前n-1位和后n-1位,反正都是1
代碼:
// Problem: C. Rings // Contest: Codeforces - Codeforces Round #741 (Div. 2) // URL: https://codeforces.com/contest/1562/problem/C // Memory Limit: 256 MB // Time Limit: 1000 ms // Data:2021-09-03 16:52:42 // By Jozky#include <bits/stdc++.h> #include <unordered_map> #define debug(a, b) printf("%s = %d\n", a, b); using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> PII; clock_t startTime, endTime; //Fe~Jozky const ll INF_ll= 1e18; const int INF_int= 0x3f3f3f3f; void read(){}; template <typename _Tp, typename... _Tps> void read(_Tp& x, _Tps&... Ar) {x= 0;char c= getchar();bool flag= 0;while (c < '0' || c > '9')flag|= (c == '-'), c= getchar();while (c >= '0' && c <= '9')x= (x << 3) + (x << 1) + (c ^ 48), c= getchar();if (flag)x= -x;read(Ar...); } template <typename T> inline void write(T x) {if (x < 0) {x= ~(x - 1);putchar('-');}if (x > 9)write(x / 10);putchar(x % 10 + '0'); } void rd_test() { #ifdef LOCALstartTime= clock();freopen("in.txt", "r", stdin); #endif } void Time_test() { #ifdef LOCALendTime= clock();printf("\nRun Time:%lfs\n", (double)(endTime - startTime) / CLOCKS_PER_SEC); #endif } int main() {//rd_test();int t;read(t);while (t--) {int n;read(n);string s;cin >> s;int pos= s.find("0");if (pos != -1) { //含0的情況if (pos < n / 2) //0出現在左半部分{printf("%d %d %d %d\n", pos + 1, n, pos + 2, n);}else //0出現在右半部分{printf("%d %d %d %d\n", 1, pos + 1, 1, pos);}}else //全1的情況{printf("%d %d %d %d\n", 1, n - 1, 2, n);}}return 0;//Time_test(); }總結
以上是生活随笔為你收集整理的cf1562 C. Rings的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么运用黄金比例(怎么运用黄金比例做手工
- 下一篇: P1174 打砖块