首页 > 其他分享 >D. Buying Jewels

D. Buying Jewels

时间:2024-07-19 14:40:15浏览次数:6  
标签:ll long solve Jewels 构造 Buying

原题链接

题解

构造题,先想特殊情况再验证

构造一个 \(n-k+1,1\)

不成立的条件是 \(2*(n-k+1)\leq n\),相当于 \(2k \geq n+2\),即 k 大于 n 的一半 ,能构造的第一多的 k 是 n ,第二多 是 \(n/2+1\) ,易得不成立

code

#include<bits/stdc++.h>
#define ll long long
using namespace std;

void solve()
{
    ll n,k;

    cin>>n>>k;

    if(n==k)
    {
        cout<<"yes\n1\n"<<1<<'\n';
    }
    else if(2LL*(n-k+1LL)<=n)
    {
        cout<<"no\n";
    }
    else
    {
        cout<<"yes\n2\n";
        cout<<n-k+1LL<<' '<<1<<'\n';
    }
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--) solve();
    return 0;
}


标签:ll,long,solve,Jewels,构造,Buying
From: https://www.cnblogs.com/pure4knowledge/p/18311432

相关文章

  • buying a SIM card and registering a mobile phone number
    Here’sasampleconversationaboutbuyingaSIMcardandregisteringamobilephonenumber:User:Hi,IneedtobuyaSIMcardandregisteramobilephonenumber.Canyouguidemethroughtheprocess?Salesperson:Ofcourse!First,weneedtochooseamo......
  • D. Buying Jewels
    D.BuyingJewelsAlicehas$n$coinsandwantstoshopatBob'sjewelrystore.Today,althoughBobhasnotsetupthestoreyet,BobwantstomakesureAlicewillbuyexactly$k$jewels.Tosetupthestore,Bobcanerectatmost$60$stalls(eachco......
  • CF103E Buying Sets(最大权闭合子图模型)
    题意简述有\(n\)个元素和\(n\)个集合,保证任意\(k\)个集合的并\(\gek\)。每个集合有权值\(a_i\),你需要选出一些集合使得集合数等于集合并大小,并在此基础上最小化选出的集合权值和。\(n\le300,|a_i|\le10^6\)。分析将集合和元素看成物品,我们发现,若选择了一个集合,则......
  • B. Buying gifts[贪心]
    Problem-1801B-Codeforces题意是需要给两个人买礼物,有n个商店,每个商店只能给一个人买,而且每个商店给两个人买的礼物的价钱也可能不同,问给两人买的礼物的最大价格之差最小是多少。我们考虑这种情况。如果当前给b买的礼物最大值为x,那么那些商店里给b礼物价格小于等于x的我们......
  • [USACO08NOV]Buying Hay S
    [USACO08NOV]BuyingHayS题目描述FarmerJohnisrunningoutofsuppliesandneedstopurchaseH(1<=H<=50,000)poundsofhayforhiscows.HeknowsN(1<=N<=100)haysuppliersconvenientlynumbered1..N.Supplierisellspackagesthatcon......
  • leetcode 771. Jewels and Stones
    You'regivenstrings J representingthetypesofstonesthatarejewels,and S representingthestonesyouhave. Eachcharacterin Sisatypeofstoneyouhave. Youwanttoknowhowmanyofthestonesyouhavearealsojewels.Thelettersin J areg......
  • 洛谷 P4544 [USACO10NOV]Buying Feed G - 题解
    https://www.luogu.com.cn/problem/P4544感觉是很没意思的DP+DS优化,以前做过几道更难的题:https://codeforces.com/contest/1788/problem/Ehttps://atcoder.jp/contests/abc288/tasks/abc288_f这种题只要是让我写总是能把代码整的伤痕累累(逃第一眼:我艹不就是一个sbDP吗......
  • P4544 Buying Feed G
    dp&单调队列优化 这个题:k<=i,决策点k可以等于i,所以在i入队后递推#include<iostream>#include<algorithm>#include<cstring>usingnamespacestd;constintN=503,M=1e4+2;#defineintlonglongintn,m,E,X[N],F[N],C[N],f[N][M];intq[N],hh,tt;......
  • [leeccode]771. Jewels and Stones
    J representingthetypesofstonesthatarejewels,and S representingthestonesyouhave. Eachcharacterin Sisatypeofstoneyouhave. Youwantto......
  • Codeforces Round 644 (Div. 3) D. Buying Shovels(数论)
    https://codeforces.com/contest/1360/problem/DD.BuyingShovels题目大意:一个人想买正好n把铲子。店内有k种包装的铲子:第i种包装正好由i把铲子组成(1≤i≤k)。这家......