打牌
題目背景:
10.19 noip
模擬t1
分析:dp or 貪心
本喵表示,這種小資料死都拍不出錯,大資料隨隨便便就錯的題,我也是喵了個咪的······打了對拍,打了暴力,然後拍了幾個小時,卵用······不吐槽了,本喵今天這個題只有
30分···貪心錯成智障······
然後,標算還是貪心,首先我們知道出對子肯定更加好,我們直接記錄乙個
cnt陣列,
cnt[x]表示x
有多少個,然後先將
1,2能出對子的盡量對子,然後從
3開始往後列舉,如果前面兩個都有多餘的一張單排,則取出當前的一張出乙個順子,因為這樣做,如果當前也有單牌,則答案會加
1,如果當前本來是順子,那麼答案不會變,並且為後面製造了多
1的,可能性,所以掃一遍就好啦,聽說還能能夠
dp做,狀態表示為,
dp[i][j]
為,當前列舉到
i然後有
j張的最優解,因為不能開下二維陣列,那麼可以用
vector
模擬動態陣列來轉移即可。
貪心:source:
/*
created by scarlyw
*/#include #include #include #include #include #include #include #include #include #include #include inline char read()
return *s++;}/*
templateinline void r(t &x)
for (x = 0; isdigit(c); c = read()) x = ((x << 2) + x << 1);
if (iosig) x = -x;
}//*/
const int out_len = 1024 * 1024;
char obuf[out_len], *oh = obuf;
inline void write_char(char c)
templateinline void w(t x)
}inline void flush()
///*
templateinline void r(t &x)
for (x = 0; isdigit(c); c = getchar()) x = ((x << 2) + x << 1) + (c ^ '0');
if (iosig) x = -x;
}//*/
const int maxn = 1000000 + 10;
int n, x, ans;
int cnt[maxn];
int main()
std::cout << ans;
return 0;
}
dp(膜拜
thhyj
大神**):
source:
#includeusing namespace std;
inline void r (int &v) while(!isdigit(ch));
while(isdigit(ch))
if(p) v = -v;
}int n;
int a[1000005];
vectordp[1000005];
int tong[1000005];
int main()
dp[0].push_back(0);
int temp;
for(register int i = 1; i <= ma; ++i)
} }printf("%d",dp[ma][tong[ma]]);
return 0;
}
NOIP模擬(10 30)T1 比賽
比賽 題目背景 10.30 noip 模擬t1 分析 暴力 將資料從小到大排序,從大到小找到第乙個滿足 a i k a i 1 的位置,那麼答案就是 n i 了,如果找不到那麼就是 n了 注意邊界 source created by scarlyw include include include i...
NOIP模擬 簡單 T1 舉辦比賽
border 0 width 330 height 86 src mstdream 舉辦了一場搶答比賽!這場搶答比賽有 n 支隊伍參賽,第 i 支隊伍將會被分配乙個隨機值 si,每乙個問題,si 值較小的隊伍會擁有優先發言權,於是 mstdream 想知道所有隊伍最小的 si 值,以便統計 但是,由...
NOIP模擬 三 T1 太空電梯
border 0 width 330 height 86 src 為了解決日漸增長的人口問題,mstdream 率領乙個小組到達火星開發新的居住地。地球到火星有一架太空電梯,電梯一次最多承載 2 個人,最大載重為 k,小組一共有 n 個人,第 i 個人重量為 vi 人們排成一隊等候上電梯。上電梯的規...