博文
Zju 1530 Find The Multiple(2006-08-02 22:52:00)
摘要:
1994302
2006-08-02 22:41:45
Accepted
1530
C++
00:00.01
440K
St.Crux
好吧,我承认,做这个题之前我犹豫了好一阵子:到底是不是dfs?不过这个数据够小的了,n<=200,递归层数<=100。
#include <cstdio>
int n, t, a[100], ac;
void dfs(int c, int s)
{
if(!s && !ac)
{
ac = 1;
for(int i = 0; i < c; i ++)
{
printf("%d", a[i]);
}
printf("\n");
}
else
{
if(c < 100 && !ac)
{
a[c] = 1;
dfs(c + 1, (s * 10 + 1) % n);
a[c] = 0;
dfs(c + 1, (s * 10) % n);
}
}
}
int main()
{
while(scanf("%d", &n) && n)
{
a[0] = 1, ac = 0;
dfs(1, 1);
}
return 0;
}......
Zju 1101 Gamblers(2006-07-30 23:41:00)
摘要:最简单的bsearch,然而我wa了无数次.......最晕的一次是输错数了-_-
ps:两个小循环要全部遍历。因为有可能是14,0,-2,-16这样的情况。
1986516
2006-07-30 23:28:21
Accepted
1101
C++
00:00.10
444K
St.Crux
#include <stdio.h>
#include <stdlib.h>
int a[1000], n, wi, wj, wk, wu;
int comp(const void *a, const void *b)
{
int aa = *(int*)a, bb = *(int*)b;
return aa > bb;
}
int main()
{
//freopen("in.txt", "r", stdin);
while(scanf("%d", &n) && n)
{
int i, k, j, u;
for(i = 0; i < n; i ++)
scanf("%d", &a[i]);
qsort(a, n, sizeof(int), comp);
wi = 536870912;
if(n < 4)
goto out;
//o(n^3 * logn)
for(i = n - 1; i >= 0; i --)
{
for(k = n - 1; k >= 0; k --)
{
if......
ZJU 1008 Gnome Tetravex (2006-07-27 00:13:00)
摘要:这注释是我写的么?忘记了.......
/* source: zju 1008 */
/* describe: dfs */
/* status: 6.83s-_- */
/* author: sqc2936 */
#include <stdio.h>
int g=0; //Game index
int n=0; //Puzzle size
int q=0; //How many different types of squares
int square[25][4]; //Source squares
int count[25]; //Quantity of a certain type of squares
int table[25]; //Solution
int place(int pos)
{
int i;
if(pos==n*n)
return 1;
for(i=0; i<q; i++)
{
if(count[i]==0)
continue;......