codeforces-1166 (div2)
所以说,遇到数学题就会翻车
A.均匀分配相同的字母就可以了。
#include <map> #include <set> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <vector> #include <string> #include <cstdio> #include <cstdlib> #include <cstring> #include <sstream> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define For(i, x, y) for(int i=x;i<=y;i++) #define _For(i, x, y) for(int i=x;i>=y;i--) #define Mem(f, x) memset(f,x,sizeof(f)) #define Sca(x) scanf("%d", &x) #define Sca2(x,y) scanf("%d%d",&x,&y) #define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z) #define Scl(x) scanf("%lld",&x); #define Pri(x) printf("%d\n", x) #define Prl(x) printf("%lld\n",x); #define CLR(u) for(int i=0;i<=N;i++)u[i].clear(); #define LL long long #define ULL unsigned long long #define mp make_pair #define PII pair<int,int> #define PIL pair<int,long long> #define PLL pair<long long,long long> #define pb push_back #define fi first #define se second typedef vector<int> VI; int read(){int x = 0,f = 1;char c = getchar();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;} const double eps = 1e-9; const int maxn = 110; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; int N,M,K; char c[100000]; int vis[maxn]; int main(){ Sca(N); int ans = 0; for(int i = 1; i <= N ; i ++){ scanf("%s",c); int id = c[0] - 'a'; vis[id]++; } for(int i = 0 ; i < 26; i ++){ int p = vis[i] / 2; int q = vis[i] - p; ans += p * (p - 1) / 2; ans += q * (q - 1) / 2; } Pri(ans); return 0; }
B.5 * 5及以上的矩阵必定合理,具体构造方法就是
aeiou
eioua
iouae
ouaei
uaeio
#include <map> #include <set> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <vector> #include <string> #include <cstdio> #include <cstdlib> #include <cstring> #include <sstream> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define For(i, x, y) for(int i=x;i<=y;i++) #define _For(i, x, y) for(int i=x;i>=y;i--) #define Mem(f, x) memset(f,x,sizeof(f)) #define Sca(x) scanf("%d", &x) #define Sca2(x,y) scanf("%d%d",&x,&y) #define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z) #define Scl(x) scanf("%lld",&x); #define Pri(x) printf("%d\n", x) #define Prl(x) printf("%lld\n",x); #define CLR(u) for(int i=0;i<=N;i++)u[i].clear(); #define LL long long #define ULL unsigned long long #define mp make_pair #define PII pair<int,int> #define PIL pair<int,long long> #define PLL pair<long long,long long> #define pb push_back #define fi first #define se second typedef vector<int> VI; int read(){int x = 0,f = 1;char c = getchar();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;} const double eps = 1e-9; const int maxn = 110; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; int N,M,K; char c[100000]; int vis[maxn]; const char A[5] = {'a','e','i','o','u'}; int main(){ Sca(N); if(N < 25){ puts("-1"); return 0; } int x,y; for(int i = 5; i <= N; i ++){ if(!(N % i)){ x = i; break; } } y = N / x; if(y < 5 || x < 5){ puts("-1"); return 0; } for(int i = 0; i < x; i ++){ int id = i % 5; for(int j = 0 ; j < y; j ++){ printf("%c",A[(id + j) % 5]); } } return 0; }
C.推式子,同正同负的情况很好推,假设a < b && a * b > 0,对于任意a,范围[a,2a]内的所有b是符合条件的,二分查找出来就可以了。
然后是不同正负的情况, a * b < 0的情况,对于任意abs(a) < abs(b),abs(b)范围[a,2a]内的也是符合条件的,同样二分查找出来
#include <map> #include <set> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <vector> #include <string> #include <cstdio> #include <cstdlib> #include <cstring> #include <sstream> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define For(i, x, y) for(int i=x;i<=y;i++) #define _For(i, x, y) for(int i=x;i>=y;i--) #define Mem(f, x) memset(f,x,sizeof(f)) #define Sca(x) scanf("%d", &x) #define Sca2(x,y) scanf("%d%d",&x,&y) #define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z) #define Scl(x) scanf("%lld",&x); #define Pri(x) printf("%d\n", x) #define Prl(x) printf("%lld\n",x); #define CLR(u) for(int i=0;i<=N;i++)u[i].clear(); #define LL long long #define ULL unsigned long long #define mp make_pair #define PII pair<int,int> #define PIL pair<int,long long> #define PLL pair<long long,long long> #define pb push_back #define fi first #define se second typedef vector<int> VI; int read(){int x = 0,f = 1;char c = getchar();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;} const double eps = 1e-9; const int maxn = 2e5 + 10; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; int N,M,K; int a[maxn]; int b[maxn]; LL cul(int *x,int *y,int n,int m,int flag){ LL ans = 0; for(int i = 1; i <= n; i ++){ int p = lower_bound(x + 1,x + 1 + n,x[i] * 2 + 1) - x - 1; int l = lower_bound(y + 1,y + 1 + m,x[i] * 2 + 1) - lower_bound(y + 1,y + 1 + m,x[i] + flag); ans += p - i + l; } return ans; } int main(){ Sca(N); int cnt1 = 0,cnt2 = 0; for(int i = 1; i <= N ; i ++){ int x = read(); if(x >= 0) a[++cnt1] = x; else b[++cnt2] = -x; } sort(a + 1,a + 1 + cnt1); sort(b + 1,b + 1 + cnt2); LL ans = 0; ans += cul(a,b,cnt1,cnt2,0); ans += cul(b,a,cnt2,cnt1,1); Prl(ans); return 0; }
D.显然序列中每个数的上下界是可以确定的,Mini = 2 ^ (i - 1) * (L + 1),Maxi = 2 ^ (i - 1) * (R + 1)
存在范围内的数必有解,知道了之后最终序列长度也可以确定了。
然后贪心的先取最小的,即所有r[i]等于1,然后贪心的将i增加
ri 需要满足 ri <= R / two[len - i - 1] - 4 * Min[i - 1] + 2 * r[i - 1] - 1
#include <map> #include <set> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <vector> #include <string> #include <cstdio> #include <cstdlib> #include <cstring> #include <sstream> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define For(i, x, y) for(int i=x;i<=y;i++) #define _For(i, x, y) for(int i=x;i>=y;i--) #define Mem(f, x) memset(f,x,sizeof(f)) #define Sca(x) scanf("%d", &x) #define Sca2(x,y) scanf("%d%d",&x,&y) #define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z) #define Scl(x) scanf("%lld",&x); #define Pri(x) printf("%d\n", x) #define Prl(x) printf("%lld\n",x); #define CLR(u) for(int i=0;i<=N;i++)u[i].clear(); #define LL long long #define ULL unsigned long long #define mp make_pair #define PII pair<int,int> #define PIL pair<int,long long> #define PLL pair<long long,long long> #define pb push_back #define fi first #define se second typedef vector<int> VI; int read(){int x = 0,f = 1;char c = getchar();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;} const double eps = 1e-9; const int maxn = 110; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; int N,K; LL L,R,M; LL a[maxn]; LL Max[maxn],two[maxn],Min[maxn],r[maxn]; int main(){ Sca(N); two[0] = 1; for(int i = 1; i <= 60; i ++) two[i] = two[i - 1] * 2; while(N--){ scanf("%lld%lld%lld",&L,&R,&M); if(L == R){ printf("1 %lld\n",L); continue; } int cnt = 2; Max[1] = Min[1] = L; int len = 0; for(int i = 2; i <= 50; i ++){ Min[i] = two[i - 2] * (L + 1); Max[i] = two[i - 2] * (L + M); if(Min[i] > R) break; if(Min[i] <= R && Max[i] >= R){ len = i; break; } } if(!len){ puts("-1"); continue; } for(int i = 1; i <= len; i ++) r[i] = 1; Min[1] = L; r[1] = L; for(int i = 2; i < len ; i ++){ r[i] = min(R / two[len - i - 1] - 4 * Min[i - 1] + 2 * r[i - 1] - 1,M); if(i != 2)Min[i] = 2 * Min[i - 1] + r[i] - r[i - 1]; else Min[i] = L + r[i]; } Prl(len); printf("%lld",L); Min[len] = R; for(int i = 2; i <= len ; i ++){ printf(" %lld",Min[i]); } puts(""); } return 0; }