注意题目中把'y'也算元音 solved
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <stack> #include <sstream> #include <set> // #pragma GCC optimize(2) //#define int long long #define rep(i,a,n) for(int i=a;i<=n;i++) #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define pi acos(-1) #define fi first #define se second //你冷静一点,确认思路再敲!!! using namespace std; typedef long long ll; typedef double db; typedef pair<int, int > PII; priority_queue< PII, vector<PII>, greater<PII> > que; stringstream ssin; // ssin << string while ( ssin >> int) const ll LINF = 0x7fffffffffffffffll; const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f; int n; map<char, int>ma; char s[N]; stack<char>ss; inline ll read() { char c=getchar();ll 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; } int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); ma['a'] = 1; ma['e'] = 1; ma['i'] = 1; ma['o'] = 1; ma['u'] = 1; ma['y'] = 1; n = read(); scanf("%s", s + 1); for (int i = 1; i <= n; ++i) { if (ss.empty()) { ss.push(s[i]); } else { char x = ss.top(); if (ma[x] && ma[s[i]]) continue; else { ss.push(s[i]); } } } stack<char>ans; while (!ss.empty()) { char x = ss.top(); ss.pop(); ans.push(x); } while (!ans.empty()) { char x = ans.top(); ans.pop(); cout << x; } puts(""); #ifndef ONLINE_JUDGE system("pause"); #endif }
注意时间不是累加而是取max solved
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <stack> #include <sstream> #include <set> // #pragma GCC optimize(2) //#define int long long #define rep(i,a,n) for(int i=a;i<=n;i++) #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define pi acos(-1) #define fi first #define se second //你冷静一点,确认思路再敲!!! using namespace std; typedef long long ll; typedef double db; typedef pair<int, int > PII; priority_queue< PII, vector<PII>, greater<PII> > que; stringstream ssin; // ssin << string while ( ssin >> int) const ll LINF = 0x7fffffffffffffffll; const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f; ll n, ans; ll a[N]; inline ll read() { char c=getchar();ll 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; } ll Min(ll a, ll b, ll c) { return min(a, min(b, c)); } int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); n = read(); ans = 1e18; for (int i = 1; i <= n; ++i) a[i] = read(); if (n == 1) { ans = min(a[1] - 1, 1000000ll - a[1]); cout << ans << ' '; } else { for (int i = 0; i <= n; ++i) { ans = min(ans, max(a[i] - 1 , 1000000 - a[i + 1])); } ans = min(ans, 1000000 - a[1]); ans = min(ans, a[n] - 1); cout << ans << ' '; } #ifndef ONLINE_JUDGE system("pause"); #endif }
模几组样例可以发现就是构造满足条件的 n2 - (n / m)2 = x 的n和m
可以拆分成(a + b) * (a - b)的形式
赛中找出了规律但是没推出式子
unsolved
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <stack> #include <sstream> #include <set> // #pragma GCC optimize(2) //#define int long long #define rep(i,a,n) for(int i=a;i<=n;i++) #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define pi acos(-1) #define fi first #define se second //你冷静一点,确认思路再敲!!! using namespace std; typedef long long ll; typedef double db; typedef pair<int, int > PII; priority_queue< PII, vector<PII>, greater<PII> > que; stringstream ssin; // ssin << string while ( ssin >> int) const ll LINF = 0x7fffffffffffffffll; const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f; ll _, x; inline ll read() { char c=getchar();ll 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; } int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); _= read(); while (_--) { x = read(); if (!x) { cout << "1 1" << ' '; continue; } // if (x == 1) { // puts("-1"); // continue; // } bool flag = 0; for (ll i = 1; i * i <= x; ++i) { // cout << i << ' '; if (x % i != 0) continue; ll xx = x / i, yy = i; if ((xx + yy) & 1) continue; // printf("%d %d ", xx, yy); ll a = (xx + yy) / 2; ll b = (xx - yy) / 2; ll n, m; n = a; if (!b) continue; m = n / b; // printf("%d %d ", n, m); if (n * n - (n / m) * (n / m) != x) continue; cout << n << " " << m << ' '; flag = 1; break; } if (!flag) puts("-1"); } #ifndef ONLINE_JUDGE system("pause"); #endif }
建虚拟源点跑最短路,原图边权值为道路过路费,虚拟点与原图中点的连边为点权,在这种建图模式下松弛操作就和普通迪杰斯特拉相同。
solved
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <stack> #include <sstream> #include <set> // #pragma GCC optimize(2) //#define int long long #define rep(i,a,n) for(int i=a;i<=n;i++) #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define pi acos(-1) #define fi first #define se second //你冷静一点,确认思路再敲!!! using namespace std; typedef long long ll; typedef double db; typedef pair<ll, ll > PII; priority_queue< PII, vector<PII>, greater<PII> > q; stringstream ssin; // ssin << string while ( ssin >> int) const ll LINF = 0x7fffffffffffffffll; const ll N = 1e6 + 5, M = 2e6 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f; ll n, m, idx; ll e[M], ne[M], w[M], h[N]; ll a[N], d[N]; bool vis[N]; inline ll read() { char c=getchar();ll 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; } void add(ll a, ll b, ll c) { e[idx] = b; w[idx] = c; ne[idx] = h[a]; h[a] = idx++; } void dij() { for (int i = 1; i < N; ++i) d[i] = 1e18; q.push({0, 0}); d[0] = 0; while (!q.empty()) { PII t = q.top(); q.pop(); int u = t.second; if (vis[u]) continue; vis[u] = 1; for (int i = h[u]; ~i; i = ne[i]) { ll v = e[i], z = w[i]; if (d[u] + z < d[v]) { d[v] = d[u] + z; q.push({d[v], v}); } } } } int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); n = read(); m = read(); mm(h, -1); for (int i = 1; i <= m; ++i) { ll u, v, w; u = read(); v = read(); w = read(); u++; v++; w = w * 2; add(u, v, w); add(v, u, w); } for (int i = 2; i <= n + 1; ++i) { a[i] = read(); add(0, i, a[i]); add(i, 0, a[i]); } dij(); for (int i = 2; i <= n + 1; ++i) cout << d[i] << " "; puts(""); #ifndef ONLINE_JUDGE system("pause"); #endif }
组合数学,太笨了推不出正确的式子
unsolved
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <stack> #include <sstream> #include <set> // #pragma GCC optimize(2) //#define int long long #define rep(i,a,n) for(int i=a;i<=n;i++) #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define pi acos(-1) #define fi first #define se second //你冷静一点,确认思路再敲!!! using namespace std; typedef long long ll; typedef double db; typedef pair<int, int > PII; priority_queue< PII, vector<PII>, greater<PII> > que; stringstream ssin; // ssin << string while ( ssin >> int) const ll LINF = 0x7fffffffffffffffll; const int N = 1e6 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f; ll _, n; ll a[N]; map<ll, ll>ma; ll jc[N], ny[N]; bool vis[N]; inline ll read() { char c=getchar();ll 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; } ll qp(ll a, ll b) { ll ans = 1ll; while (b) { if (b & 1) { ans = ans * a % mod; } a = a * a % mod; b = b / 2; } return ans; } void init() { // 预处理阶乘和逆元 jc[0] = 1; jc[1] = 1; ny[1] = 1; for (ll i = 2; i <= 1e6; ++i) { jc[i] = jc[i - 1] * i % mod; ny[i] = qp(jc[i], mod - 2); } } ll c(ll n, ll m) { if (n == 0 || n == m) return 1; return jc[m] * ny[n] % mod * ny[m - n] % mod; } int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); init(); n = read(); for (int i = 1; i <= n; ++i) a[i] = read(); sort(a + 1, a + 1 + n); for (int i = 2; i <= n; ++i) { if (a[i] == a[i - 1]) ma[a[i]] = ma[a[i - 1]]; else ma[a[i]] = i - 1; } ll ans = 0; for (int i = 1, j = 1; i <= n; i = j + 1) { while (a[i] == a[j + 1]) j++; if (j == n) break; ll m = ma[a[j]]; // ans += a[i] * m % mod * jc[n] % mod * qp(m, mod - 2) % mod; ans += a[i] * (j - i + 1) % mod * jc[n] % mod * qp(n - i + 1, mod - 2) % mod; ans %= mod; } cout << ans << ' '; #ifndef ONLINE_JUDGE system("pause"); #endif }