爲嘛每次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;
}