摘要:状态压缩,先将生成的所有状态排序,然后枚举即可。/*PROG : holsteinLANG : C*/# include <stdio.h># include <stdlib.h>struct scoop{int a[30];};int V, G, r[(1 << 17) + 5];struct scoop g[17], v;/***************************************************/int bcnt(int x){ int ret = 0; while (x) { ++ret; x &= x-1; ..
阅读全文
摘要:首先两重 for 循环对可能取的值约分,分子分母分别存放,根据比较分数大小的方法排序,然后按顺序输出(相同的只输出一个);/*PROG : frac1LANG : C++*/# include <stdio.h># include <stdlib.h># define MAXN (160 * 160)/***************************************************/int num[MAXN], den[MAXN], r[MAXN], m = 0;int cmp(const void *xx, const void *yy){ in
阅读全文
摘要:直接枚举就行了,不带回溯的搜索。/*PROG : hammingLANG : C++*/# include <stdio.h># define id(x) ((x)>>3)# define of(x) ((x)&0x7)# define get(x) ((h[id(x)]>>of(x))&0x1)# define set(x) (h[id(x)] |= (0x1<<of(x)))int n, b, d;char h[(1<<5) + 1];int sol[70];/***************************
阅读全文
摘要:八皇后问题,最大输入13,单case,时限1s;和 HDOJ 不同的是:Do not precalculate the value and print it (or even find a formula for it); that's cheating. Work on your program until it can solve the problem properly. If you insist on cheating, your login to the USACO training pages will be removed and you will be disqual
阅读全文
摘要:没打表。/*PROG : sprimeLANG : C++*/# include <stdio.h>/*******************************/char isp(int x){ int i; if (x%2 == 0) return x == 2; if (x%3 == 0) return x == 3; if (x%5 == 0) return x == 5; for (i = 7; i*i < x; i+= 2) if (x%i == 0) return 0; return 1;}void g(int x, int r...
阅读全文
摘要:素回文数,打表。。打表输出# include <math.h># include <time.h># include <stdio.h># define id(x) ((x)>>3)# define of(x) ((x)&0x7)# define get(x) ((pt[id(x)]>>of(x))&0x1)# define set(x) (pt[id(x)] |= (0x1<<(of(x))))# define MAXN 100000000char pt[(MAXN>>3) +1];void
阅读全文
摘要:用的BFS,将每一个数字除以4,得到四种不同的状态:0 1 2 3,为了实现判重,用2位表示一个状态,整个钟表需要2*9 = 18位,不大;题解中第二种做法貌似是推理得到了一般解法。 1 /* 2 PROG : clocks 3 LANG : C++ 4 */ 5 6 # include <cstdio> 7 # include <cstring> 8 # include <queue> 9 10 using namespace std; 11 12 int ss; 13 char vis[0x3FFFF + 0x1]; 14 int pre[0x3FFFF
阅读全文
摘要:这道题是 IOI95 的题目,直接做感觉有难度,主要原因是题目描述的六种形式是否是完备的,其实这个问题不需要考虑(题目已经明确指出了,或许已经被证明了),剩下的就是枚举了;1Y,这道题考的是生成排列的方法和模拟中细节的处理。 1 /* 2 PROG : packrec 3 LANG : C++ 4 */ 5 # include <cstdio> 6 # include <cstdlib> 7 8 int h[5][2]; 9 int pp[25][5], k = 0; 10 int solu[6*24*16+5][2], n = 0, m = 0; 11 12 /**.
阅读全文
摘要:预处理+暴力,4.8s险过;注意长度为N的等差数列是指总共有N个数,所以公差上界为2*M*M/(N-1);/*PROG : ariprogLANG : C*/# include <stdio.h># include <stdlib.h># define MAXN (62505 * 2)int N, M, ans;char f[MAXN];short p[MAXN], q[MAXN];void pre(void){ int i, j, x; for (i = 0; i <= 250; ++i) for (j = i; j <= 250; ++j) { x =.
阅读全文
摘要:题意比较难懂。有编号为 1 2 3。。。S 的牛棚,其中C个有牛而其余的没有,现在所有牛棚护栏都被大雨淋坏了,而提供牛棚护栏的商人只能提供一定数目(M个)的护栏(长度则随意,想要多长就能提供多长),为了节省money,FJ决定在所有有牛的棚子都修好的前提下,尽可能使得所需护栏的总长度最小(或者被护栏围住的牛棚总数最少)。首先如果S<=M,完全可以只要S个就行了,是满足要求且最少的;如果S>M,就需要把一些不连续的含牛的牛棚用一个大的护栏围住,其中包含不含牛的牛棚,要使这些不含牛的被围牛棚总的数目最少,就尽量使同一个护栏下不连续的片段尽可能小,就有了贪心的思路。太绕口了。/* PRO
阅读全文
摘要:manacher求最长子串。/*PROG : calfflacLANG : C++*/# include <cstdio># include <cctype># define N 20000 + 5int n;char s[N];int Min(int x, int y){ return x < y ? x : y;}int manacher(char *s, int len, int &st){ int n = len*2+1; char t[2 * N]; /* insert '#' in string s to form a 2*le
阅读全文
摘要:模拟题,给出一个 n×n 的字符块的两个状态(分别为初始态和目标态)和几种操作,问目标态最少是由初始态的哪个操作完成的,WA 3 次。/*PROG: transformLANG: C++*/# include <cstdio># include <cstring># define N 10 + 5void print(char s[][N], int n){ for (int i = 0; i < n; ++i) puts(s[i]);}/* rotate 90 degrees clockwise */void rotate(char s[][N], i
阅读全文
摘要:直接暴力也可,用的二分搜索+枚举,文件输入的调试了很久,后来不知道怎么就对了。二分的是写成求最小符合条件的下标;/*PROG: namenumLANG: C++*/# include <cstdio># include <cstring># include <cstdlib># define N 5000 + 10# define LEN 20int len[N];char s[N][LEN];char tab[30];void build(void){ for (int i = 'A'; i < 'S'; ++i) t
阅读全文
摘要:给出 n 和 s (十进制),打印 s 后面 n 个在 2-10 进制中至少两个进制下为回文数的十进制表示。/*PROG: dualpalLANG: C++*/# include <cstdio># include <cstring>int n, s;void strRev(char *s){ char ch; int len = strlen(s), mid = len / 2; for (int i = 0; i < mid; ++i) ch = s[i], s[i] = s[len-1-i], s[len-1-i] = ch;}void to(int ba.
阅读全文
摘要:给出一个数 n(十进制),求出 1-300 范围内所有平方(n 进制)为回文串的数,并打印。/*PROG: palsquareLANG: C++*/# include <cstdio># include <cstring># define N 300void strRev(char *s){ char ch; int len = strlen(s), mid = len / 2; for (int i = 0; i < mid; ++i) ch = s[i], s[i] = s[len-1-i], s[len-1-i] = ch;}void to(int bas.
阅读全文
摘要:把所有区间(如果能)合并起来,求最长连续区间长度和最长间隔长度(两个区间之间,如果只有一个区间为0);/*PROG: milk2LANG: C++*/# include <cstdio># include <cstdlib># define N 5000 + 10struct val{ int s, t;} a[N];int n;int cmp(const void *x, const void *y){ val *p = (val*)x; val *q = (val*)y; if (p->s == q->s) return p->t - q->
阅读全文
摘要:这道题理解了题目的含义就很简单了;如果题目改成每次只统计一端,遇到不同时开始统计另一端,并且只有相邻两次统计的(可以转化)为同一种颜色时,才能累加,难度会很高,可能要DP了;/*PROG: beadsLANG: C++*/# include <cstdio># include <cstring># define N 350 + 10int n;char s[N];int count(char *s, int k){ int ret = 0; int i = k; int j = (k-1+n) % n; char cur; while(ret < n &&
阅读全文
摘要:这道题挺不好写的,题目是说给出一个年份范围,统计这个范围内星期一到星期日为 13 号的个数。/*PROG: fridayLANG: C++*/# include <cstdio>const char daytab[2][13] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};int isLeap(int year){ return year%4 == 0 && year%100 != 0 || y
阅读全文