摘要:1. 第一次做位运算的题,参考了这段经典代码(n皇后问题):void Queen(int row, int ld, int rd)
{ int pos, p; int upperlim = (1 > 1); } } else ++sum;
}2. 以下是代码:/*
ID: dollar4
PROG: checker
LANG: C++
*/
#include #include #include #include #include #include #include using namespace std;
ofstream fou...
阅读全文
摘要:1.从数学的角度: 1.首位只能是质数2 3 5 72.其余位只能是1,3,7,93.若n=1,直接输出2,3,5 7直接DFS 1~9,加入当前数末尾,并判断是不是素数,是则递归处理下一位数,不是则回溯,直到depth>n。不会超时。2. 这道题折磨了我好久,一直出现Execution error: Your program (`sprime') exited with signal #11 (segmentation violation [maybe caused by accessing memory out of bounds, array indexing out of
阅读全文
摘要:1. 无数遍TLE的题,快疯了,最后没办法,只能看别人的代码,最好的一个代码,写了下来,但是还有一点地方不太明白,这是一种新的方法,以下是代码/*
ID: dollar4
PROG: pprime
LANG: C++
*/
#include #include #include #include #include using namespace std;
int modify(int x)
{ int t = x; x /= 10; while (x > 0) { t = t * 10 + x % 10; x /= 10...
阅读全文
摘要:1. 动态规划,f[i,j]=Max{f[i+1,j],f[i+1,j+1]}+a[i,j] (1
#include #include #include #include using namespace std;
long long num[1010][1010];
long max(long a, long b)
{ if (a > b) return a; else return b;
}
int main()
{ ofstream fout ("numtri.out"); ifstream fin ("numtri.in"); ...
阅读全文
摘要:1. 用dfs,[A][B][C]为三个状态,且只有6个操作,a倒b,a倒c,b倒a,b倒c,c倒a,c倒b。知道用深搜了,但是还是不知道怎么写,看了别人的代码,才会写dfs()这个函数了。其实确定深搜了之后,写这个函数的时候,不需要考虑递归是怎么进行的,只需要考虑这次和下一次的操作过程即可。2. 以下是代码:/*
ID: dollar4
PROG: milk3
LANG: C++
*/
#include #include #include #include #include using namespace std;
int a, b, c, p = 0, isin[20];
in...
阅读全文
摘要:1. 枚举可以算出来,但是肯定超时,所以要剪枝,以等差数列a+nb说明;2. 几个可以剪枝的地方:b的范围是从1~2*m*m/(n-1); a的范围是0~2*m*m - (n-1) * b然后循环判断是不是pq了剪枝不是很充分,但是最慢3秒多给过了,哈哈3.以下是代码:/*
ID: dollar4
PROG: ariprog
LANG: C++
*/
#include #include #include #include #include using namespace std; int main()
{ ofstream fout ("ariprog.out"); ...
阅读全文
摘要:1. 这道题有好多种解法,看NOCOW,用枚举,DFS,BFS都能求解。我看到这个题的时候,连最基本的枚举怎么做都想不出来,差距呐。。。;2. 我挑选了解题报告中代码最短的读懂然后写出来了:/*
ID: dollar4
PROG: clocks
LANG: C++
*/
#include #include #include #include #include #include #include using namespace std;
#define FOR(x) for (c[x] = 0; c[x] > temp; a[i] = temp / 3 % 4;
...
阅读全文
摘要:1.因为只有4个方块,所以枚举每个方块的选择顺序和放置方向(横放还是纵放),放置方式只有题目给出的6中基本模式,分别算出不同模式下最小的面积,更新最优解。第4、5个在本质上其实是一样。如图,不同模式对应的最小面积如下:设w1,w2,w3,w4表示4个方块的横长,h1,h2,h3,h4表示4个方块的纵长。w,h表示最小。1:w=w1+w2+w3+w4;h=max(h1,h2,h3,h4)2:w=max(w1+w2+w3,w4);h=max(h1,h2,h3)+h43:w=max(w1+w2,w3)+w4;h=max(h1+h3,h2+h3,h4)4:w=w1+w2+max(w3,w4);h=ma
阅读全文
摘要:1. 枚举,注意里边的几个剪枝,标在代码中了2. 我的代码:/*
ID: dollar4
PROG: crypt1
LANG: C++
*/
#include #include #include #include #include using namespace std;
int num[10], n;
bool cmp(int a, int b)
{ return a > n; int i, j, k, l, m, s1, s2, s3, s4, s5; int cnt = 0, mm, nn, mn; for (i = 0; i > num[i]...
阅读全文
摘要:1. 输入带回车符,空格,标点符号的字符串:while (fin >> temp) { str += temp; str += " "; }
unsigned int len = str.size();
str.resize(len - 1);2. 判断是不是回文3. 以下是代码:/*
ID: dollar41
PROG: calfflac
LANG: C++
*/
#include
#include
#include
#define maxn 20010
using namespace std;
char str1[maxn],str2[max...
阅读全文
摘要:1. 这道题想多了,想得很复杂,其实就是把输入的一排数按照从小到大的顺序排列,然后得到相邻两个数之间的差,按从大到小的顺序排序,用这个数组所有元素的和减去前m-1个数,然后再加上m,就得到结果2. 以下是我的代码:/*
ID: dollar4
PROG: barn1
LANG: C++
*/
#include #include #include #include #include using namespace std;
bool cmp1(int a, int b)
{ return a > b;
}
bool cmp2(int a, int b)
{ retur...
阅读全文
摘要:1. 贪心,其他没啥说的2. 我的代码:/*
ID: dollar4
PROG: milk
LANG: C++
*/
#include #include #include #include #include using namespace std;
struct Node
{ int price; int num;
} node[5000];
bool cmp(Node a, Node b)
{ return a.price > n >> m; for (i = 0; i > node[i].price >> node[i].num; sor...
阅读全文
摘要:1. 直接用了上道题的函数,另外,进制转换:string trans(int a)
{ string str1 = ""; int tmp; while (a) { tmp = a % base; if (tmp #include #include #include #include using namespace std;
int n, s;
bool checkp(string str)
{ int len = str.size(); for (int i = 0; i > n >> s; ...
阅读全文
摘要:1. 进制转换+回文判断+int与char之间相互转换;以下是代码:/*
ID: dollar4
PROG: palsquare
LANG: C++
*/
#include #include #include #include #include using namespace std;
int base;
bool checkp(string str)
{ int len = str.size(); for (int i = 0; i > base; for (i = 1; i #include #include #include #include ...
阅读全文
摘要:1. 比较简单,但是用到了文件读写,终于明白了给的test代码中的fout和fin是什么意思了,哈哈;2. 如果按照一般的思路,肯定会超时,所以把dict转换成数字,这样的算法效率是固定的以下是代码:/*
ID: dollar4
PROG: namenum
LANG: C++
*/
#include #include #include #include #include using namespace std;
char get_num(char a)
{ switch (a) { case 'A' : return '2'; cas...
阅读全文
|