http://www.javashuo.com/article/p-xzlkndvy-dh.htmlhtml
題意就是給你兩個字符串,而後若是s,t的對應位上的字母要麼都是元音,要麼都是輔音,,就輸出Yes反之輸出No,,長度不等確定輸出的是No,,,c++
#include <bits/stdc++.h> //#include <iostream> //#include <cstdio> //#include <cstdlib> //#include <string.h> #define aaa cout<<ans<<endl; #define endl '\n' #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; const int inf = 0x3f3f3f3f;//1061109567 const ll linf = 0x3f3f3f3f3f3f3f; const double eps = 1e-6; const double pi = 3.14159265358979; const int maxn = 2e5 + 5; const int maxm = 2e5 + 5; const int mod = 1e9 + 7; inline ll read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } bool check(char a, char b) { if(a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') if(b == 'a' || b == 'e' || b == 'i' || b == 'o' || b == 'u') return true; else return false; else if(b != 'a' && b != 'e' && b != 'i' && b != 'o' && b != 'u')return true; else return false; } int main() { // freopen("233.in" , "r" , stdin); // freopen("233.out" , "w" , stdout); ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); string s, t;cin >> s >> t; if(s.length() != t.length())cout << "No" << endl; else { int len = s.length(); for(int i = 0; i < len; ++i) { if(!check(s[i], t[i])) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; } return 0; }
題意是給你n個數,有兩種操做,一個是刪除任意的一個數,另外一個是將任意的一個數加一,,對於 每一個數的操做 最多有k種,,總的操做數是m,,,而後問你m個操做後最大的平均值是多少,,git
首先爲了儘量的增長平均數,要刪除一些小的數,,暴力遍歷可能刪除的數的個數,,顯然最多刪除的個數是n-1或者是m,,因此遍歷的邊界是 min(m, n - 1)
,,數組
而後依次刪去最小的數(預先排序一下),,刪掉這個數後,算一下此時剩下數的平均值,,,而後和上一次的結果比較一下,取最大就行spa
#include <bits/stdc++.h> //#include <iostream> //#include <cstdio> //#include <cstdlib> //#include <string.h> #define aaa cout<<233<<endl; #define endl '\n' #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, ull> pii; const int inf = 0x3f3f3f3f;//1061109567 const ll linf = 0x3f3f3f3f3f3f3f; const double eps = 1e-6; const double pi = 3.14159265358979; const int maxn = 1e5 + 5; const int maxm = 2e5 + 5; const ll mod = 1e9 + 7; inline int read() //快讀 { int ans=0; char ch=getchar(); while(!isdigit(ch)) ch=getchar(); while(isdigit(ch)) ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar(); return ans; } ll a[maxn]; int main() { // freopen("233.in" , "r" , stdin); // freopen("233.out" , "w" , stdout); // ios_base::sync_with_stdio(0); // cin.tie(0);cout.tie(0); ll n, k, m; n = read(); k = read(); m = read(); for(int i = 1; i <= n; ++i)a[i] = read(); sort(a + 1, a + 1 + n); ll sum = 0; for(int i = 1; i <= n; ++i)sum += a[i]; long double ans = (long double)(sum + min(k * n, m)) / (long double)(n); for(int i = 1; i <= min(m, n - 1); ++i) { sum -= a[i]; long double res = (long double)(sum + min(m - i, k * (n - i))) / (long double)(n - i); ans = max(ans, res); } printf("%.20f", (double)ans); return 0; }
題意是給你一個區間長度爲 \(2^n\)長,,而後一個數組a[k],a[i]表示第i個位置加一,,可能有a[i]是相等的,,而後有兩種操做,一種是子區間全爲零時操做的代價爲A,,不然代價爲 \(B*num_{l,r}*len_{l, r}\),,,問你整個區間的最小操做代價,,code
題解是遞歸+二分求解,,,htm
我一開始想到了遞歸來求,,可是本身寫二分求區間[l, r]的 \(num_{l, r}\) 時老是寫爆,,,最後看了題解纔想起來還有stl裏的 lower_bound
和 upper_bound
能夠直接二分找到,,,QAQblog
#include <bits/stdc++.h> //#include <iostream> //#include <cstdio> //#include <cstdlib> //#include <string.h> #define aaa cout<<233<<endl; #define endl '\n' #define pb push_back using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, ull> pii; const int inf = 0x3f3f3f3f;//1061109567 const ll linf = 0x3f3f3f3f3f3f3f; const double eps = 1e-6; const double pi = 3.14159265358979; const int maxn = 1e5 + 5; const int maxm = 2e5 + 5; const ll mod = 1e9 + 7; inline ll read() //快讀 { ll ans=0; char ch=getchar(); while(!isdigit(ch)) ch=getchar(); while(isdigit(ch)) ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar(); return ans; } vector<ll> a; ll n, k, A, B; #define len (r-l+1) #define mid ((l+r)>>1) ll getnum(int l, int r) { l = lower_bound(a.begin(), a.end(), l) - a.begin(); r = upper_bound(a.begin(), a.end(), r) - a.begin(); return r - 1 - l + 1; } ll solve(int l, int r) { ll num = getnum(l, r); if(!num)return A; if(l == r) { if(num) return B * num * 1; else return A; } ll a = solve(l, mid); ll b = solve(mid + 1, r); // cout << a << b << "---" << endl; if(num)return min(a+b, (ll)(B * len * num)); else return min(a+b, A); } int main() { // freopen("233.in" , "r" , stdin); // freopen("233.out" , "w" , stdout); // ios_base::sync_with_stdio(0); // cin.tie(0);cout.tie(0); n = read(); k = read(); A = read(); B = read(); for(int i = 1; i <= k; ++i) { int t = read(); a.pb(t); } sort(a.begin(), a.end()); printf("%lld", solve(1, (1<<n))); return 0; }