1. HDU - 5914
意识到最贪心的保留最多饼干的方案是 1 2 3 5 8 13 21 ..... 一个斐波那契数列,任选两个筷子都成不了三角形
所以给的N每大于其中的一个数就意味着我们能多保留一个筷子,其余的都不要
#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 ", x) #define Prl(x) printf("%lld ",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; int a[10] = {0,1,2,3,5,8,13,21}; int main(){ int T; Sca(T); int Case = 1; while(T--){ Sca(N); printf("Case #%d: ",Case++); int ans = 0; for(int i = 1; i <= 6 ; i ++){ if(N >= a[i]) ans++; } Pri(N - ans); } return 0; }
标题写着后缀数组但是并不
很显然最后一个是 > 还是 < 可以直接判断出来,然后从前往后判断,如果前一个字母比后一个大就是 > ,小就是 < ,如果相同的话就相当于两个字符串都去掉第一位比较,直接取上一个答案即可。
#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 ", x) #define Prl(x) printf("%lld ",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 = 1e6 + 10; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; int N,M,K; char str[maxn]; char ans[maxn]; int main(){ int T; Sca(T); while(T--){ Sca(N); scanf("%s",str + 1); if(str[N - 1] < str[N]) ans[N - 1] = '<'; else ans[N - 1] = '>'; for(int i = N - 2; i >= 1; i --){ if(str[i] < str[i + 1]) ans[i] = '<'; else if(str[i] > str[i + 1]) ans[i] = '>'; else ans[i] = ans[i + 1]; } ans[N] = '