签到
来源:互联网 发布:淘宝卖家客户电话 编辑:程序博客网 时间:2024/04/18 06:08
1、HDU 5753 Permutation Bo
刚开始连题意没搞懂然后样例都搞不出来,搞懂题意后暴力找到规律推出来个公式,但是时间过去好久了,菜的抠脚啊。。。
题解的做法好厉害,%%%
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <vector>#include <stack>#include <map>#include <cmath>#include <cctype>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef unsigned int uint;typedef pair<int, int> Pair;const ull mod = 1e9 + 7;const int INF = 0x7fffffff;const int maxn = 1e3 + 10;int n;double c[maxn];int main(){#ifdef __AiR_H freopen("in.txt", "r", stdin);#endif // __AiR_H while (scanf("%d", &n) != EOF) { double sum = 0; for (int i = 1; i <= n; ++i) { scanf("%lf", &c[i]); sum += c[i]; } if (n == 1) { printf("%f\n", c[1]); } else { double ans = ((c[1] + c[n]) * 3.0 + (sum - c[1] - c[n]) * 2.0) / 6.0; printf("%f\n", ans); } } return 0;}
2、HDU 5762 Teacher Bo
这道题怎么做都能过。。。
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <vector>#include <stack>#include <map>#include <cmath>#include <cctype>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef unsigned int uint;typedef pair<int, int> Pair;const ull mod = 1e9 + 7;const int INF = 0x7fffffff;const int maxn = 1e5 + 10;struct Node { int x, y;};Node node[maxn];int N, M;map<int, int> Map;int distance(int x1, int y1, int x2, int y2);int main(){#ifdef __AiR_H freopen("in.txt", "r", stdin);#endif // __AiR_H int T; scanf("%d", &T); while (T--) { Map.clear(); scanf("%d%d", &N, &M); for (int i = 0; i < N; ++i) { scanf("%d%d", &node[i].x, &node[i].y); } bool flag = false; if ((N*(N-1)/2) >= 2*M-1) { flag = true; } else { for (int i = 0; i < N; ++i) { for (int j = i+1; j < N; ++j) { int t = distance(node[i].x, node[i].y, node[j].x, node[j].y); if (Map[t] == 0) { Map[t] = 1; } else { flag = true; break; } } if (flag) { break; } } } if (flag) { printf("YES\n"); } else { printf("NO\n"); } } return 0;}int distance(int x1, int y1, int x2, int y2){ return abs(x1-x2) + abs(y1-y2);}
3、HDU 5805 NanoApe Loves Sequence
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <vector>#include <stack>#include <map>#include <cmath>#include <cctype>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef unsigned int uint;typedef pair<int, int> Pair;const ull mod = 1e9 + 7;const int INF = 0x7fffffff;const int maxn = 1e5 + 10;int A[maxn];int n;int main(){#ifdef __AiR_H freopen("in.txt", "r", stdin);#endif // __AiR_H int T; scanf("%d", &T); while (T--) { scanf("%d", &n); int Max1 = -1, pos1 = 0, pos2 = 0, pos3 = 0, Max2 = -1, Max3 = -1; for (int i = 0; i < n; ++i) { scanf("%d", &A[i]); if (i > 0) { int t = abs(A[i] - A[i-1]); if (t > Max1) { Max3 = Max2; pos3 = pos2; Max2 = Max1; pos2 = pos1; Max1 = t; pos1 = i; } else if (t > Max2) { Max3 = Max2; pos3 = pos2; Max2 = t; pos2 = i; } else if (t > Max3) { Max3 = t; pos3 = i; } } } ull ans = 0; if (pos1 == 1) { ans += Max2; } else { ans += Max1; } for (int i = 1; i < n-1; ++i) { int t = abs(A[i+1] - A[i-1]); if (pos1 == i && pos2 == i+1) { ans += max(Max3, t); } else if (pos2 == i && pos1 == i+1) { ans += max(Max3, t); } else if ((pos1 == i && pos3 == i+1) || (pos1 == i+1 && pos3 == i)) { ans += max(Max2, t); } else if ((pos2 == i && pos3 == i+1) || (pos2 == i+1 && pos3 == i)) { ans += max(Max1, t); } else if (pos1 == i || pos1 == i+1) { ans += max(Max2, t); } else { ans += max(Max1, t); } } if (pos1 == n) { ans += Max2; } else { ans += Max1; } printf("%I64d\n", ans); } return 0;}
4、HDU 5776 sum
Provider: HallStattMia
预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续子列可以组成m的倍数
另外,利用抽屉原理,我们可以得到,一旦n大于等于m,答案一定是YES
所以根据抽屉原理,这道题很好过
我是用了尺取法来做
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <vector>#include <stack>#include <map>#include <cmath>#include <cctype>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef unsigned int uint;typedef pair<int, int> Pair;const ull mod = 1e9 + 7;const int INF = 0x7fffffff;const int maxn = 1e5 + 10;int num[maxn];int main(){#ifdef __AiR_H freopen("in.txt", "r", stdin);#endif // __AiR_H int T; while (scanf("%d", &T) != EOF) { while (T--) { int n, m; scanf("%d%d", &n, &m); bool flag = false; for (int i = 0; i < n; ++i) { scanf("%d", &num[i]); num[i] %= m; if (num[i] == 0) { flag = true; } } queue<int> Q; int sum = 0; if (!flag) { for (int i = 0; i < n; ++i) { Q.push(num[i]); sum += num[i]; if (sum%m == 0) { flag = true; break; } while (sum > m) { sum -= Q.front(); Q.pop(); } if (sum%m == 0) { flag = true; break; } } } if (flag) { printf("YES\n"); } else { printf("NO\n"); } } } return 0;}
5、UVa 11292 Dragon of Loowater
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <vector>#include <stack>#include <map>#include <cmath>#include <cctype>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef unsigned int uint;typedef pair<int, int> Pair;const ull mod = 1e9 + 7;const int INF = 0x7fffffff;int n, m;vector<int> V1, V2;int main(){#ifdef __AiR_H freopen("in.txt", "r", stdin);#endif // __AiR_H while (scanf("%d%d", &n, &m) != EOF && !(n ==0 && m == 0)) { V1.clear(), V2.clear(); int num; while (n--) { scanf("%d", &num); V1.push_back(num); } while (m--) { scanf("%d", &num); V2.push_back(num); } if (n > m) { printf("Loowater is doomed!\n"); } else { sort(V1.begin(), V1.end()), sort(V2.begin(), V2.end()); ull ans = 0; int Size1 = V1.size(), Size2 = V2.size(); int pos1 = 0, pos2 = 0; while (pos1 < Size1 && pos2 < Size2) { if (V2[pos2] >= V1[pos1]) { ans += V2[pos2]; ++pos1; ++pos2; } else { ++pos2; } } if (pos1 == Size1) { printf("%llu\n", ans); } else { printf("Loowater is doomed!\n"); } } } return 0;}
6、UVa 11729 Commando War
假设我们交换两个相邻的任务 X 和 Y(交换前 X 在 Y 之前,交换后 Y 在 X 之前),不难发现其他任务的完成时间没有影响,那么这两个任务呢?
情况一:交换之前,任务 Y 比 X 先结束,如图(a)所示。不难发现,交换之后 X的结束时间延后,Y 的结束时间提前,最终答案不会变好
情况二:交换之前,X 比 Y 先结束,因此交换后答案变好的充要条件是:交换后 X 的结束时间比交换前 Y 的结束时间早(交换后 Y 的结束时间肯定变早了)
如图(b)所示。这个条件可以写成 B[Y]+B[X]+J[X] < B[X]+B[Y]+J[Y],化简得 J[X] < J[Y] ,这就是我们贪心的依据
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <vector>#include <stack>#include <map>#include <cmath>#include <cctype>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef unsigned int uint;typedef pair<int, int> Pair;const ull mod = 1e9 + 7;const int INF = 0x7fffffff;const int maxn = 1e3 + 10;struct Node { int B, J;};Node node[maxn];int N;bool cmp(Node a, Node b);int main(){#ifdef __AiR_H freopen("in.txt", "r", stdin);#endif // __AiR_H int Case = 0; while (scanf("%d", &N) != EOF && N != 0) { for (int i = 0; i < N; ++i) { scanf("%d%d", &node[i].B, &node[i].J); } sort(node, node+N, cmp); ull ans = 0; ull B_sum = 0; for (int i = 0; i < N; ++i) { B_sum += node[i].B; ull ans_t = B_sum + node[i].J; if (ans_t > ans) { ans = ans_t; } } printf("Case %d: %llu\n", ++Case, ans); } return 0;}bool cmp(Node a, Node b){ return a.J > b.J;}
7、Codeforces Gym 100860A AutoCoder
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <vector>#include <stack>#include <map>#include <set>#include <cmath>#include <cctype>#include <bitset>#include <ctime>using namespace std;#define REP(i, n) for (int i = 0; i < (n); ++i)typedef long long ll;typedef unsigned long long ull;typedef unsigned int uint;typedef pair<int, int> Pair;const ull mod = 1e9 + 7;const int INF = 0x7fffffff;int main(){#ifdef __AiR_H freopen("in.txt", "r", stdin);#endif // __AiR_H ll n; scanf("%I64d", &n); if (n == 0) { printf("0\n"); } else { --n; ll ans = 0, t = 0; while (n) { if (n <= 2) { ans += 1; break; } if (n%2 == 0) { t = n / 2; ans += t * (t+1) / 2; n = (n - 2) / 2; } else { t = (n+1) / 2; ans += t * (t+1) / 2; n = (n-3) / 2; } } printf("%I64d\n", ans); } return 0;}
0 0
- 签到
- 签到
- 签到....
- 签到
- 签到
- 签到
- 签到
- 签到
- 签到
- 签到
- 签到
- 签到
- 签到
- 签到
- 签到
- 签到
- 签到
- 签到
- Glide总结
- 142. Linked List Cycle II
- php多文件上传
- stored property "text" without initial value prevents synthesized initializers
- 图像缩放算法(用过了邻近差值算法)
- 签到
- java中的Static class
- 为什么C++类定义中,数据成员不能被指定为自身类型,但可以是指向自身类型的指针或引用?
- POJ-1573-Robot Motion
- C++函数重载案例
- POJ-1905-Expanding Rods【二分】【计算几何】
- Win10配置Apache The requested operation has failed
- 不定积分表
- 第三章--自定义控件