为嘛每次D题图论的都过不了,难道3年没搞acm就退化成这样了。
暴力,坑爹,输出格式不对,WA了两次 = =!
暴力搞,这个数据范围能过
C题24 Game
给定n求1-n之和为24的方式,如果不能输出NO。
自己解出N=4 5 6 7的方式,另外别的都能转化为这几种
坑爹,WA了4次,急着交的结果。。。。
代码:
#include<iostream> #include<cstdio> #include<memory.h> #include<queue> #include<cmath> #include<stack> #include<cstdlib> #include<vector> #include<string> #include<cstring> #include<map> using namespace std; #define Clear(f, nr) memset(f, nr, sizeof(f)) const int SIZE = 5005; const int MSIZE = 10000; typedef long long ll; const int INF = 1 << 30; void gao(int x) { if(x == 4) { puts("1 * 2 = 2"); puts("2 * 3 = 6"); puts("4 * 6 = 24"); } else if(x == 5) { puts("4 * 5 = 20"); puts("2 - 1 = 1"); puts("1 + 3 = 4"); puts("20 + 4 = 24"); } else if(x == 6) { puts("4 * 6 = 24"); puts("5 + 1 = 6"); puts("2 * 3 = 6"); puts("6 - 6 = 0"); puts("24 - 0 = 24"); } else if(x == 7) { puts("4 * 5 = 20"); puts("7 - 6 = 1"); puts("2 - 1 = 1"); puts("1 * 1 = 1"); puts("1 + 3 = 4"); puts("20 + 4 = 24"); } } int main() { int n; while(cin >> n) { if(n < 4) puts("NO"); else { puts("YES"); int x = (n - 4) % 4 + 4; int cnt = 0; for(int i = x + 1; i <= n; i += 4) { printf("%d - %d = 1\n", i + 1, i); printf("%d - %d = 1\n", i + 3, i + 2); printf("1 - 1 = 0\n", i + 1, i); cnt ++; } gao(x); while(cnt --) { puts("0 + 24 = 24"); } } } }
D题Two Sets
看到2Set我还真以为用2Set解,后来想想应该是2分匹配图,结果图左右两边分不出来,构不出图,弱爆了。。。唉。。早上起来又掉rating了
看了别人的解题报告,用的是直接暴力,能在a里处理的都放a集合,否则放入b集合,在b里开始遍历,如果b-x不在就去a里拿,如果a中也没有就输出NO,艾玛。。。。。
事实证明有时候想太多也不好
别人代码:
#include <cstdio> #include <set> #include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; int n, a, b; set<int> f, g; set<int> :: iterator it; vector<int> c; map<int,int> mp; int res[100005]; int main(){ scanf("%d%d%d", &n, &a, &b); for(int i=1;i<=n;i++){ int x; scanf("%d", &x); f.insert(x); mp[x]= i; } for(it=f.begin();it!=f.end();++it){ int x= (*it); if(f.find(a-x)==f.end()) c.push_back(x); } for(int i=0;i<(int)c.size();i++){ f.erase(c[i]); g.insert(c[i]); } c.clear(); while(!g.empty()){ it= g.begin(); int x= (*it); if(g.find(b-x)!=g.end()){ res[mp[x]]= 1; res[mp[b-x]]= 1; g.erase(x); if(x*2!=b) g.erase(b-x); } else if(f.find(b-x)!=f.end()){ res[mp[x]]= 1; res[mp[b-x]]= 1; f.erase(b-x); if(2*(b-x)!=a) f.erase(a-(b-x)); g.erase(x); if(2*(b-x)!=a) g.insert(a-(b-x)); } else{printf("NO\n"); return 0;} } printf("YES\n"); for(int i=1;i<=n;i++) printf("%d ", res[i]); printf("\n"); return 0; }