From c502ecdd958cd6f5f1b99232aa707aa8448d419d Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 19 Aug 2017 17:14:37 +0800 Subject: [PATCH] Add CCPC Pre Online Contest 2017. Thanks to Richard for providing code. Unfortunately we still didn't pass the contest again this year. Harder training! Better score! --- .../1003_Richard.cpp | 66 ++++++++ .../1004_Richard.cpp | 152 ++++++++++++++++++ .../1005_Richard.cpp | 54 +++++++ 3 files changed, 272 insertions(+) create mode 100644 HDOJ/CCPC Pre Online Contest 2017/1003_Richard.cpp create mode 100644 HDOJ/CCPC Pre Online Contest 2017/1004_Richard.cpp create mode 100644 HDOJ/CCPC Pre Online Contest 2017/1005_Richard.cpp diff --git a/HDOJ/CCPC Pre Online Contest 2017/1003_Richard.cpp b/HDOJ/CCPC Pre Online Contest 2017/1003_Richard.cpp new file mode 100644 index 0000000..4e2cf62 --- /dev/null +++ b/HDOJ/CCPC Pre Online Contest 2017/1003_Richard.cpp @@ -0,0 +1,66 @@ +//#include "stdafx.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +const int maxn = 3005; +bool a[maxn][maxn]; + +int main() +{ + int T; + scanf("%d", &T); + for(int t=0;t +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define LL long long +//#define DEBUG +using namespace std; + +const int MAXN = 1000005 ; +const long long mod = 1e9+7; +char s[2 * MAXN]; +char t[MAXN]; +char tmp[MAXN]; +int ls; +int lt; +int nx[MAXN]; +int nm[MAXN]; +int mk[MAXN]; +void getNext(); +void kmp(); + +void init() { + memset(s, 0, sizeof(s)); + memset(t, 0, sizeof(t)); + memset(nx, 0, sizeof(nx)); + memset(nm, 0, sizeof(nm)); + memset(mk, 0, sizeof(mk)); +} + +//int KMP(char A[], char B[], int C[]) +//{ +// +// int num = 0; +// int Alen = strlen(A); +// int Blen = strlen(B); +// +// int i = 0; +// int j = -1; +// C[0] = -1; +// while (i < Alen) { +// if (B[i] == B[j] || j == -1) { +// i++; +// j++; +// C[i] = j; +// } +// else +// j = C[j]; +// } +// +// i = 0; +// j = 0; +// while (i < Alen) { +// if (j == -1 || A[i] == B[j]) { +// i++; +// j++; +// } +// else +// j = C[j]; +// if (j == Blen) +// num++; +// } +// return num; +//} +//拆分计算 +void kmp() { + + int j = lt; + for (int i = ls - 1; i >= 0; i--) { + + while (t[j - 1] != s[i] && j < lt) { + j = nx[j]; + mk[lt - j]++; + } + if (t[j - 1] == s[i]) { + j--; + nm[lt - j]++; + } + if (j <= 0) { + i += lt - j - 1; + j = lt; + } +#ifdef DEBUG + printf("%c", nm[i]); +#endif + } +} +void getNext() { + + nx[lt - 1] = lt; + for (int i = lt - 2; i >= 0; i--) { + + int j = nx[i + 1]; + + while (t[j - 1] != t[i] && j < lt) { + j = nx[j]; + } + + if (t[j - 1] == t[i]) { + nx[i] = j - 1; + } + else { + nx[i] = lt; + } +#ifdef DEBUG + printf("%c", nx[i]); +#endif + } +} + +int main() { + int T; + scanf("%d", &T); + + for(int c=0;c 0; i--) { + mem += mk[i]; + sum += (LL)i * (LL)(nm[i] + mem)%mod; + sum %= mod; +#ifdef DEBUG + printf("%lld\n", sum); +#endif + } + printf("%lld\n", sum); + } + return 0; +} \ No newline at end of file diff --git a/HDOJ/CCPC Pre Online Contest 2017/1005_Richard.cpp b/HDOJ/CCPC Pre Online Contest 2017/1005_Richard.cpp new file mode 100644 index 0000000..f4317f4 --- /dev/null +++ b/HDOJ/CCPC Pre Online Contest 2017/1005_Richard.cpp @@ -0,0 +1,54 @@ +//#include "stdafx.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define LL long long +LL t[1000010]; +#define MAXN 1e9 +int Count = 0; +//直接取结果 +int calc(int n){ + return std::lower_bound(t, t + Count, n) - t; +} + +int main() { + + int T; + LL p = 0; + //初始化整个数组 + memset(t, 0, sizeof(t)); + + for (LL i = 4; i < 1000010; i++) { + + if ((i % 4)==0) { + t[i] = i * i / 8; + p = t[i] - t[i - 1]; + } + else if ((i & 1)==0) { + + t[i] = t[i - 1] + p; + } + else { + t[i] = t[i - 1] + (i + 1) / 4 - 1; + } + Count = i; + if (t[i] > MAXN) + break; + } + + cin >> T; + + while (T--) { + int n; + cin >> n; + cout << calc(n) << endl; + } +} \ No newline at end of file