#include
#include
using namespace std;
#define FOR(X,Y,Z) for (int X=Y; X
const int MAXN=6e4+1,INF=2147483647,MOD=1000000009;
int F[1001] = { 0,469,139,1086,768,860,1200,837,837,507,117,1136,1228,231,1205,337,7,954,954,862
,522,885,416,746,1136,117,25,1022,1022,154,1161,771,453,545,885,522,991,661,661
,979,887,547,910,441,771,1161,142,50,50,1024,156,1163,773,455,547,887,524,993
,993,46,364,272,1269,295,1163,156,546,864,864,1204,841,841,841,841,841,841,841
,841,841,841,841,523,615,955,592,1061,731,341,341,249,1246,272,1140,133,523,841
,749,409,409,878,548,158,1177,1269,272,1246,378,48,48,366,274,1271,297,1165,158
,548,866,774,774,411,880,550,160,1179,1271,274,1248,380,380,770,1088,996,656,1019
,550,880,1270,251,251,591,228,697,367,1314,996,1088,91,1065,1065,735,345,27,119
,459,96,565,235,1182,1182,1090,750,1113,644,974,27,345,253,1250,1250,382,52,52
,52,52,52,52,52,52,52,52,52,1049,75,943,1273,326,644,552,552,189,658
,328,1275,957,1049,52,1026,158,158,548,866,774,434,797,328,658,1048,29,29,369
,6,475,145,1092,774,866,1206,843,843,513,123,1142,1234,237,1211,343,13,960,960
,868,528,891,422,752,1142,123,31,1028,1028,160,1167,777,459,551,891,528,997,667
,667,985,893,553,916,447,777,1167,148,56,56,1030,162,1169,779,461,553,893,530
,999,999,52,370,370,370,370,370,370,370,370,370,370,370,839,509,119,1138,1230
,233,1207,1207,877,487,169,261,601,238,707,377,1324,1324,1232,892,1255,786,1116,169
,487,395,55,55,524,194,1141,823,915,1255,892,24,1031,1031,12,1257,917,1280,811
,1141,194,512,420,420,57,526,196,1143,825,917,1257,894,26,26,416,734,642,302
,665,196,526,916,1234,1234,237,1211,343,13,960,642,734,1074,711,711,381,1328,1010
,1102,105,1079,211,1218,828,828,736,396,396,396,396,396,396,396,396,396,396,396
,786,1104,1012,672,1035,566,896,896,578,670,1010,647,1116,786,396,78,170,170,533
,64,394,784,1102,1010,670,1033,564,564,174,1193,1285,288,1262,394,64,1011,693,693
,353,716,247,577,967,1285,1193,853,1216,1216,209,599,917,825,485,848,379,709,1099
,1099,1191,194,1168,300,1307,917,599,691,1031,1031,562,892,1282,263,171,1168,194,1062
,55,55,1074,1166,169,1143,275,1282,892,574,666,666,1029,560,560,560,560,560,560
,560,560,560,560,560,652,992,629,1098,768,378,60,60,1057,83,951,1281,334,652
,560,220,583,583,913,1303,284,192,1189,215,1083,76,466,466,558,898,535,1004,674
,284,1303,58,398,398,1266,259,649,967,875,535,898,429,759,759,441,533,873,510
,979,649,259,1278,33,33,396,1264,257,647,965,873,533,896,427,427,37,1056,1148
,151,1125,257,1264,874,556,556,216,579,110,440,830,1148,1056,716,1079,1079,72,462
,462,462,462,462,462,462,462,462,462,462,99,568,238,1185,867,959,1299,1299,830
,1160,213,531,439,99,462,1330,323,323,5,97,437,74,543,213,1160,842,934,934
,1297,828,1158,211,529,437,97,460,1328,1328,938,620,712,1052,689,1158,828,438,120
,120,1117,143,1011,4,394,712,620,280,643,643,973,26,344,252,1249,275,1143,136
,526,526,618,958,595,1064,734,344,26,118,458,458,1326,319,709,1027,935,595,958
,489,819,819,501,593,593,593,593,593,593,593,593,593,593,593,263,1210,892,984
,1324,961,93,93,483,801,709,369,732,263,593,983,1301,1301,304,1278,1278,1278,1278
,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278
,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278
,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278
,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278
,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278,1278
,1278,1278,331,649,557,217,580,111,441,441,123,215,555,192,661,331,1278,960,1052
,1052,78,946,1276,329,647,555,215,578,109,109,1056,738,830,1170,807,1276,946,556
,238,238,1235,261,1129,122,512,830,738,398,761,761,1091,144,462,370,30,393,1261
,254,644,644,736,1076,713,1182,852,462,144,236,576,576,107,437,437,437,437,437
,437,437,437,437,437,437,777,414,883,553,163,1182,1274,1274,300,1168,161,551,869
,777,437,800,331,331,1278,960,1052,55,1029,161,1168,778,460,460,120,483,14,344
,734,1052,960,620,983,983,1313,366,684,592,252,615,146,476,866,866,958,1298,935
,67,1074,684,366,458,798,798,329,659,1049,30,1275,935,1298,829,1159,1159,841,933
,1273,910,42,1049,659,341,433,433,796,327,657,1047,28,1273,933,1296,827,827,437
,119,119,119,119,119,119,119,119,119,119,119,987,1317,370,688,596,256,619,619
,949,2,320,228,1225,251,1119,112,502,502,594,934
};
int D[1001] = {1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,1,0,1
,0,0,1,0,1,0,1,1,1,0,1,0,1,0,1,1,0,0,1
,0,1,0,0,1,0,1,0,0,1,1,0,1,0,1,0,1,1,1
,0,1,0,1,0,0,1,0,1,1,0,1,1,1,1,1,1,1,1
,1,1,1,0,1,0,1,1,0,1,1,0,1,0,0,1,0,1,0
,1,1,1,0,1,0,1,0,1,1,0,0,1,0,1,0,0,1,0
,1,0,0,1,1,0,1,0,1,0,1,1,1,0,1,0,1,0,0
,1,0,1,1,0,1,1,0,1,0,1,0,1,1,0,1,0,1,0
,1,1,0,1,1,0,1,0,0,1,0,1,0,1,1,1,0,0,0
,0,0,0,0,0,0,0,0,1,0,0,1,0,1,0,0,1,1,0
,1,0,1,0,1,1,1,0,1,0,1,0,0,1,0,1,1,0,1
,1,0,1,0,1,0,1,1,0,1,0,1,0,1,1,0,1,1,0
,1,0,0,1,0,1,0,1,1,1,0,1,0,1,0,1,1,0,0
,1,0,1,0,0,1,0,1,0,0,1,1,0,1,0,1,0,1,1
,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0
,1,1,0,1,0,1,0,1,1,0,1,1,0,1,0,0,1,0,1
,0,1,1,1,0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,1,0,1,1,0,1,0,1,1
,0,0,1,0,1,0,1,0,0,0,1,0,1,0,1,1,0,1,0
,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1
,0,0,1,0,1,1,0,1,0,1,0,0,0,1,1,1,1,1,1
,1,1,1,1,1,0,1,1,0,1,0,1,1,0,0,1,0,1,0
,1,0,0,0,1,0,1,0,1,1,0,1,0,0,1,0,0,1,0
,1,0,1,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,1
,0,1,0,1,0,0,0,1,0,1,0,1,0,0,1,1,0,1,0
,1,1,0,1,0,1,1,0,0,1,0,1,0,1,0,0,0,1,0
,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,1
,0,1,0,1,0,0,1,0,0,1,0,1
};
bool Judge (int Num) {
if (Num % 7 == 0)
return 1;
while (Num) {
if (Num % 10 == 7) return 1;
else Num /= 10;
}
return 0;
}
int main() {
freopen("seven.in", "r", stdin);
freopen("seven.out", "w",stdout);
int n, Now = 0, Cnt = 0;
bool Dir;
scanf ("%d",&n);
Now = F[n/1000000];
Dir = D[n/1000000];
FOR (i,n/1000000*1000000+1,n+1) {
if (!Dir) {
Now --;
if (Now == 0) Now = 1337;
if (Judge (i)) Dir = 1;
} else if (Dir) {
Now ++;
if (Now == 1338) Now = 1;
if (Judge (i)) Dir = 0;
}
}
printf ("%d\n",Now);
return 0;
}
2.正方形计数
枚举两个点,求出剩余两个点,判断是全为有点的
注意有负坐标的点
#include
#define LOCAL
const int maxn = 510;
const int maxm = 200 + 510;
int point[maxm][maxm];
int n;
struct Point {
int x, y;
};
Point map[maxn];
inline void init() {
#ifdef LOCAL
freopen("count.in","r",stdin);
freopen("count.out","w",stdout);
#endif
scanf("%d", &n);
for (int i = 1; i <= n; ++ i) {
scanf("%d%d", &map[i].x, &map[i].y);
point[map[i].x + 200][map[i].y + 200] = true;
}
}
inline void solve() {
int ans = 0;
for (int i = 1; i < n; ++ i) {
for (int j = i + 1; j <= n; ++ j) {
int x1 = map[i].x , x2 = map[j].x;
int y1 = map[i].y , y2 = map[j].y;
int x3 = y2 - y1 + x1;
int y3 = x1 - x2 + y1;
int x4 = x2 + y2 - y1;
int y4 = x1 - x2 + y2;
if (point[x3 + 200][y3 + 200] && point[x4 + 200][y4 + 200])
ans ++;
x3 = 2 * x1 - x3;
y3 = 2 * y1 - y3;
x4 = 2 * x2 - x4;
y4 = 2 * y2 - y4;
if (point[x3 + 200][y3 + 200] && point[x4 + 200][y4 + 200])
ans ++;
}
}
printf("%d\n", ans / 4);
}
int main() {
init();
solve();
}
3.前缀单词
这道题直接排序(算前缀集合) ,然后简单的计算
#include
#include
#include
#include
using namespace std;
string a[55];
long long pos[55],tot;
bool v[55][55];
long long f[55];
bool c(string a,string b) {
if(a.size() > b.size()) {
string buf = a;
a = b;
b = buf;
}
if(b.find(a) != 0) return 1;
else return 0;
}
int main() {
int n;
freopen("prefix.in","r",stdin);
freopen("prefix.out","w",stdout);
cin >> n;
for(int i = 1; i <= n; ++ i)cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; ++ i) {
v[0][i] = 1;
v[i][0] = 1;
f[i] = 1;
for(int j = 1; j <= n; ++ j) {
v[i][j] = c(a[i],a[j]);
}
}
f[0] = 0;
for(int i = 1; i <= n; i++) {
for(int j = i; j<= n; j++)
if(v[i][j]) {
f[j] += f[i];
}
}
long long ans = 0;
for(int i = 1; i <= n; ++ i) ans += f[i];
cout<<(ans + 1);
}
4.数列
要发现一个前缀和的关系,具体参见Luogu(这道题考场上我没有想出来)
#include
#include
#include
const int maxn = 100005;
struct data{
int s,id;
bool operator < (const data &u) const {return sint n,p[maxn];
bool get[maxn];
void halt(){
puts("-1"); exit(0);
}
int main(){
freopen("sequence.in","r",stdin);
freopen("sequence.out","w",stdout);
scanf("%d", &n);
a[0].s = 0;
for (int i = 1; i <= n; ++ i){
int scanf("%d", &x); a[i].s = a[i - 1].s + x, a[i].id = i;
}
std::sort(a + 1, a + 1 + n);
if (a[1].s <= 0) halt();
for (int i = 1; i < n; ++ i) if (a[i].s == a[i + 1].s) halt();
for (int i = 1; i <= n; ++ i) p[a[i].id] = i;
int ans = 0;
std::memset(get, 0, sizeof get);
for (int i = 1; i <= n; ++ i) if (!get[i]){
get[i] = 1;
for (int x = p[i]; x != i; x = p[x])
ans ++, get[x] = 1;
}
printf("%d", ans);
return 0;
}