Codeforces Round #313 (Div. 2) (ABCD)
来源:互联网 发布:轻论坛cms 编辑:程序博客网 时间:2024/05/23 18:37
A
题意:
给你n种货币,问用这n中货币能否组成所有的价值,如果可以输出-1,否则输出最小的不能组成的价值。
解析:
做这个题目的时候还思考了一会儿,后来发现,所有如果没有1的话,那么就算有任何值(大于1)都无法构成1,而如果有1的话,就可以构成任何值,所以这题就算判断有没有1出现,有1就输出-1,没有就输出1。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1e6 + 10;const int INF = 0x3f3f3f3f;bool dp[MAXN*2];int n, A[1005];int main() { while(scanf("%d", &n) != EOF) { memset(dp, false, sizeof(dp)); for(int i = 1; i <= n; i++) { scanf("%d", &A[i]); dp[A[i]] = true; } if(dp[1]) printf("%d\n", -1); else printf("%d\n", 1); } return 0;}
B
题意:
给你1个相框其长度为A1,宽度为B1,再给你两幅画,其长宽分别为(A2, B2),(A3, B3),问你能否把两张画塞进相框
解析:
只有8种情况很好考虑,直接暴力枚举过。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1e6 + 10;const int INF = 0x3f3f3f3f;int w, h;int A[2], B[2];bool judge() { int s1 = A[0]*A[1], s2 = B[0]*B[1]; if(s1 + s2 > w*h) return false; for(int i = 0; i < 2; i++) { for(int j = 0; j < 2; j++) { if(max(A[i], B[j]) <= w && A[i^1] + B[j^1] <= h) return true; if(max(A[i], B[j]) <= h && A[i^1] + B[j^1] <= w) return true; } } return false;}int main() { while(scanf("%d%d", &w, &h) != EOF) { scanf("%d%d", &A[0], &A[1]); scanf("%d%d", &B[0], &B[1]); if(w > h) swap(w, h); printf("%s\n", judge() ? "YES" : "NO"); } return 0;}
C
题意:
给你一个6边形的6个边,每个角都是120°,现在问你这个6边形内,有多少个正3角形,每个正3角形。
解析:
这题首先想到的是补足思想,把6边形的3个角补全,然后再减去这3个正3角形,那么补全后的6边形肯定是一个正3角形,其每个边长为
(a1+a2+a3) ,减去每个小正3角形,每个小正3角形的边长分别为a1 ,a3 ,a5 ,最后答案可以推算出是(a1+a2+a3)2−a21−a23−a25
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const int INF = 0x3f3f3f3f;int a[10];int main() { //freopen("in.txt", "r", stdin); while(scanf("%d", &a[1]) != EOF) { for(int i = 2; i <= 6; i++) { scanf("%d", &a[i]); } int len = a[1] + a[2] + a[3]; int S = len * len; int s1 = a[1]*a[1]; int s2 = a[3]*a[3]; int s3 = a[5]*a[5]; int ans = (S - s1 - s2 - s3); printf("%d\n", ans); } return 0;}
D
题意:
给出两个等长的字符串,定义一种判断两个字符串相等的方法,判断两个字符串是否相等。
解析:
因为是每次都将字符串分为等长的两个字符串 ,所以字符串的长度必须是偶数时才能继续划分,奇数时就要一个个的字符进行判断。
注意:
要用记忆化搜索来优化搜索,不如会超时。
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <map>#include <algorithm>#define make make_pairusing namespace std;string A, B;map<pair<string,string>, bool> dp;bool dfs(string p, string q) { if(dp.count(make(p, q))) return dp[make(p, q)]; if(p == q) return dp[make(p, q)] = true; if(p.size() == 1) return dp[make(p, q)] = false; if(p.size() != q.size()) return dp[make(p, q)] = false; int len = p.size(); int mid = len / 2; string L1, R1, L2, R2; if(len % 2 == 0) { L1 = p.substr(0, mid); R1 = p.substr(mid, len-mid); L2 = q.substr(0, mid); R2 = q.substr(mid, len-mid); if(dfs(L1, L2) && dfs(R1, R2) || dfs(L1, R2) && dfs(R1, L2)) return dp[make(p, q)] = true; } return dp[make(p, q)] = false;}int main() { while(cin >> A >> B) { dp.clear(); printf("%s\n", dfs(A, B) ? "YES" : "NO"); } return 0;}
0 0
- Codeforces Round #313 (Div. 2) (ABCD)
- Codeforces Round #Pi (Div. 2) (ABCD)
- Codeforces Round #316 (Div. 2)(ABCD)
- Codeforces Round #298 (Div. 2) 解题报告 (ABCD)
- Codeforces Round #315 (Div. 2) (ABCD题)
- Codeforces Round #396 (Div. 2)题解(ABCD)
- Codeforces Round #429 (Div. 2) 题解(ABCD)
- Codeforces Beta Round #67 (Div. 2) ABCD
- Codeforces Round #191 (Div. 2) ABCD
- Codeforces Round #193 (Div. 2) ABCD
- Codeforces Round #211 (Div. 2) ABCD
- Codeforces Round #208 (Div. 2) ABCD
- Codeforces Round #220 (Div. 2) ABCD
- Codeforces Round #222 (Div. 2) ABCD
- Codeforces Round #257 (Div. 2) ABCD
- Codeforces Round #258 (Div. 2)[ABCD]
- Codeforces Round #264 (Div. 2) | ABCD
- Codeforces Round #302 (Div. 2) (ABCD题解)
- Android 序列化 Parcelable 跟 Serializable
- undefined reference to `boost::system::generic_category()
- oracle,通过plsql创建用户表空间和所属用户示例
- Docker ssh远程连接使用
- 【尝鲜版】驱动级网站防护软件-浪潮云戟
- Codeforces Round #313 (Div. 2) (ABCD)
- BZOJ 1004 [HNOI2008]Cards 置换+burnside定理+逆元
- 如何在Eclipse里面更新添加主题
- os.rename()导致WindowsError: [Error 183]的问题
- 多线程(二)
- 在VirtualBox中安装Ubuntu14报错:Failed to open a session for the virtual machine,Unable to load R3……
- Android性能分析优化 - TraceView介绍
- SQL常用语句总结
- 关于C++二维指针