PS:大概是又傻了,读题啊。
#include<bits/stdc++.h> #define ll long long #define P pair<int,int> #define pb push_back #define lson root << 1 #define INF (int)2e9 + 7 #define maxn (int)1e5 + 7 #define rson root << 1 | 1 #define LINF (unsigned long long int)1e18 #define mem(arry, in) memset(arry, in, sizeof(arry)) using namespace std; ll n; bool check(ll mid){ ll res = 0; ll tp = n; while(tp){ if(tp < mid) break; res += mid; tp = tp - mid; tp = tp - tp / 10; } res += tp; if(res * 2 >= n) return true; return false; } int main() { cin >> n; ll l = 1, r = n; for(int i = 1; i <= 100; i++){ ll mid = (l + r) >> 1; if(check(mid)) r = mid; else l = mid + 1; } cout << l << endl; return 0; }
PS:又FST了,读题的锅。从头依次寻找合法的位置放就行了。因为所有能放的位置在贪心的过程中都会被找到,故一定是最优解。
#include<bits/stdc++.h> #define ll long long #define P pair<int,int> #define pb push_back #define lson root << 1 #define INF (int)2e9 + 7 #define maxn (int)1e5 + 7 #define rson root << 1 | 1 #define LINF (unsigned long long int)1e18 #define mem(arry, in) memset(arry, in, sizeof(arry)) using namespace std; char mp[2][200]; int main() { for(int i = 0; i < 2; i++) scanf("%s", mp[i]); int n = strlen(mp[0]); int res = 0; for(int i = 0; i < n - 1; ){ int t = 0; if(mp[0][i] == 'X') t++; if(mp[1][i] == 'X') t++; if(mp[0][i + 1] == 'X') t++; if(mp[1][i + 1] == 'X') t++; if(t > 1){ i++; continue; } else{ i += 2; res++; } int tt = 0; if(i < n - 2){ if(mp[0][i] == 'X') tt++; if(mp[1][i] == 'X') tt++; if(t == 0 && tt == 0){ i += 1; res++; } } } cout << res << endl; return 0; }
PS:去重排列的公式得知道。然后暴力枚举,可以用10个循环,也可以深搜。写搜索很考验状态的设计,还有考虑什么时候终止,在哪里计算答案等等。
PS:非本人原创
#include<bits/stdc++.h> #define ll long long #define P pair<int,int> #define pb push_back #define pop pop_back #define lson root << 1 #define INF (int)2e9 + 7 #define maxn (int)1e5 + 7 #define rson root << 1 | 1 #define LINF (unsigned long long int)1e18 #define mem(arry, in) memset(arry, in, sizeof(arry)) using namespace std; int a[20]; ll n, res, fac[20]; vector<int> d; //记录每个数使用了多少次 void Inite() { res = 0; fac[0] = 1; for(int i = 1; i < 20; i++) fac[i] = fac[i - 1] * i; } ll C(ll x, ll y){ return fac[x] / fac[y] / fac[x - y]; } void DFS(int x){ if(x == 10){ ll s = 0, tp = 0; for(auto o : d) s += o; tp = fac[s]; for(auto o : d) tp /= fac[o]; if(!a[0]){ res += tp; return; } else{ for(int i = 1; i <= a[0]; i++) res += tp * C(s + i - 1, i); return; } } if(!a[x]) DFS(x + 1); for(int i = 1; i <= a[x]; i++){ d.pb(i); DFS(x + 1); d.pop(); } } int main() { Inite(); cin >> n; while(n) { a[n % 10]++; n /= 10; } DFS(1); cout << res << endl; return 0; }