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!
This commit is contained in:
Kirigaya Kazuto 2017-08-19 17:14:37 +08:00
parent 425180d386
commit c502ecdd95
3 changed files with 272 additions and 0 deletions

View File

@ -0,0 +1,66 @@
//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdlib>
using namespace std;
const int maxn = 3005;
bool a[maxn][maxn];
int main()
{
int T;
scanf("%d", &T);
for(int t=0;t<T;t++)
{
int n;
scanf("%d", &n);
for (int i = 0; i<n; i++)
{
for (int j = i + 1; j<n; j++)
{
int temp;
scanf("%d", &temp);
a[i][j] = a[j][i] = temp;
}
}
int flag = 1;
for (int i = 0; i<n; i++)
{
if (flag == 0)
break;
for (int j = i + 1; j<n; j++)
{
if (flag == 0)
break;
for (int k = i + 1; k<j; k++)
{
if (a[i][j] == a[i][k] && a[i][j] == a[k][j])
{
flag = 0;
break;
}
}
}
}
if (flag == 1)
puts("Great Team!");
else
puts("Bad Team!");
}
return 0;
}

View File

@ -0,0 +1,152 @@
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//
//#include "stdafx.h"
#include <cstdio>
#include <string>
#include <cmath>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#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<T;c++){
init();
scanf("%s%s", tmp, t);
lt = strlen(t);
for (int i = 0; i < lt; i++)
s[i] = ',';
s[lt] = '\0';
strcat(s, tmp);
ls = strlen(s);
getNext();
kmp();
long long sum = 0;
int mem = 0;
for (int i = lt; i > 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;
}

View File

@ -0,0 +1,54 @@
//#include "stdafx.h"
#include <cstdio>
#include <string>
#include <cmath>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
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;
}
}