随笔分类 -  水水更健康

摘要:题意很简单就不说了。解题的关键就是这个公式answer=n/(m^(n-1));要用到大数的乘法。然后java水过。import java.util.*;import java.math.*;public class Main { public static BigInteger gcd (BigInteger a, BigInteger b) { if (a.mod(b).equals(BigInteger.valueOf(0))) return b; return gcd(b, a.mod(b)); } public static void main(String[] args) ... 阅读全文
posted @ 2013-10-22 19:52 xindoo 阅读(145) 评论(0) 推荐(0)
摘要:题目链接 题目就是让你输出n个数的序列,要保证该序列是递增的,并且第i个数的前面不能保护它的约数,我直接先对前100000的素数打表,然后输出前n个,so easy。//cf 191 B#include #include int ans[100005];bool vis[10000000];int main(){ int cnt = 1; for (int i = 2; i 100000) { break; } } int n; while (scanf("%d", &n) != EOF) { ... 阅读全文
posted @ 2013-07-04 22:18 xindoo 阅读(275) 评论(0) 推荐(0)
摘要:题目链接 给你一串只有0和1的数字,然后对某一区间的数翻转1次(0变1 1变0),只翻转一次而且不能不翻转,然后让你计算最多可能出现多少个1。 这里要注意很多细节 比如全为1,要求必须翻转,这时候我们只要翻转一个1就可以了,对于其他情况,我们只要计算区间里面如果0多于1,将其翻转后计算1的总数,然后取最大值。//cf 191 A//2013-07-04-22.13#include #include #include using namespace std;int a[105];int cnt[105];int main(){ int n; while (scanf("%d" 阅读全文
posted @ 2013-07-04 22:14 xindoo 阅读(116) 评论(0) 推荐(0)
摘要:题目链接题目大意是有一个含n个数的数组,你可以通过+1或者-1的操作使得其中的数是1--n中的数,且没有重复的数。既然是这样的题意,那么我就应该把原数组中的数尽量往他最接近1--n中的位置放,然后求差绝对值之和,但有多个数,怎么使他们和最小,这样就要对其进行排序了,直接按大小给它们安排好位置,然后计算。//CF 285C//2013-06-06-19.57#include #include #include using namespace std;const int maxn = 3*100001;int a[maxn];int main(){ int n; while (scan... 阅读全文
posted @ 2013-06-06 20:05 xindoo 阅读(201) 评论(0) 推荐(0)
摘要:题目链接题目就是让你找出一个数组中可以将这个数组中所有数整除的数,很明显,如果存在,这个数肯定是最小的一个。//cf 299A//2013-06-05-20.51#include #include #include using namespace std;const int maxn = 100005;int a[maxn];int main(){ int n; while (scanf("%d", &n) != EOF) { int m = 0x3f3f3f3f; for (int i = 0; i < n; i++) { ... 阅读全文
posted @ 2013-06-05 20:59 xindoo 阅读(164) 评论(0) 推荐(0)
摘要:题目链接就是给你两个日期,让你求两个日期之间差多少天。我先算出两个日期分别是公元多少天,然后相减得到结果。//cf 304B//2013-06-05-18.38#include #include int y, m, d;int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int loop(int y){ if (y%4 == 0 && y%100 != 0 || y%400 == 0) return 1; return 0;}int count(){ int sum = 0; fo... 阅读全文
posted @ 2013-06-05 18:41 xindoo 阅读(157) 评论(0) 推荐(0)
摘要:题目链接虽然不知道怎么做,但是AC还是没有问题的。大概就是循环n次,从m加到m-n/2 除了最后一个数,每个都加两次。#include int main(){ int n, m; while (scanf("%d %d", &m, &n) != EOF) { int ans = 0; int t = m; for (int i = n; i != 1; i -= 2) { ans += t*2; t--; } ans += t; pri... 阅读全文
posted @ 2013-06-03 19:45 xindoo 阅读(139) 评论(0) 推荐(0)
摘要:题目链接//poj 2105//2013-05-01-21.10#include char s[34];int a[8] = {128, 64, 32, 16, 8, 4, 2, 1};int main(){ int n; scanf("%d", &n); while (n--) { scanf("%s", s); int ans = 0; int f = 1; for (int i = 0; i < 32; i++) { if (s[i] == '1') ... 阅读全文
posted @ 2013-05-27 21:06 xindoo 阅读(150) 评论(0) 推荐(0)
摘要:A. Whose sentence is it?代码://codeforces 312 A//2013-05-01-19.12#include #include char str[102];int main(){ int n; scanf("%d", &n); getchar(); while (n--) { int f = 0; int r = 0; gets(str); int l = strlen(str); if (str[0] == 'm' && str[1] == 'i' && st... 阅读全文
posted @ 2013-05-27 19:17 xindoo 阅读(142) 评论(0) 推荐(0)
摘要:题目链接//hdoj 4551//2013-05-26-20.52#include int day[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 judge(int y){ if (y%4 == 0 && y % 100 != 0 || y % 400 == 0) return 1; else return 0;}int gcd(int x, int y){ if (x%y == 0) re... 阅读全文
posted @ 2013-05-26 20:49 xindoo 阅读(137) 评论(0) 推荐(0)
摘要://hdoj 4554//2013-05-26-19.47#include int turn(int x){ int f = 1; if (x >1; int b = x-a; a = turn(a); b = turn(b); printf("%d %d\n", a+b, a-b); } return 0;} 阅读全文
posted @ 2013-05-26 19:43 xindoo 阅读(155) 评论(0) 推荐(0)
摘要:题目链接输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其他字符顺序不变),得到字符串是。代码://2013-05-22-07.47#include #include const int maxn = 100005;char s[maxn], t[maxn];int main(){ while (scanf("%s %s", s, t) != EOF) { int l1 = strlen(s); int l2 = strlen(t); int j = 0; for (int i = 0; i < l2 && j <... 阅读全文
posted @ 2013-05-22 07:58 xindoo 阅读(141) 评论(0) 推荐(0)
摘要:题目链接题意: 有n个正整数组成的序列,给定一个整数s,求长度最短的连续序列,使他们的和大于或等于s。 关于这个题目,有多种的解法,如果枚举起点和终点,时间复杂度为O(n^3),但如果我们用一个数组B把一段数的和存起来,B[i] = sum(a[1].....a[i])。这样就可以把时间复杂度降到O(n^2)。 还有更好的方法,因为B数组是递增的,我们只需要枚举终点,然后二分查找起点即可,时间复杂度进一步降到O(n*logn),但我们可以继续优化,由于B[i]-s是递增的,枚举的起点也是递增的,换句话说,满足条件的位置也是递增的,因此我们可以怎么写代码://2013-05-21-20.3... 阅读全文
posted @ 2013-05-21 12:42 xindoo 阅读(188) 评论(0) 推荐(0)
摘要:题目链接刘汝佳算法竞赛经典入门训练指南p42代码1:#include #include #include using namespace std;int next(int n, int k){ stringstream ss; ss n) s = s.substr(0, n); int ans = 0; stringstream ss2(s); ss2 >> ans; return ans;}int main(){ int t; int n, k; cin>>t; while (t--) { cin... 阅读全文
posted @ 2013-05-20 10:36 xindoo 阅读(132) 评论(0) 推荐(0)
摘要:#include#includeint a[150],b[150],t[150];int pr[150];void prime(){ int i, j, f, cnt = 1; pr[0] = 2; for(i = 3; ;i++) { f = 1; for(j = 2;j * j 120) break; }}void change(int l,int *p){ int cnt = 0; for(int i = l;i >= 0;i--) { p[cnt++] = t[i]; ... 阅读全文
posted @ 2013-01-12 02:36 xindoo 阅读(169) 评论(1) 推荐(0)