zoukankan      html  css  js  c++  java
  • 【CF1023B】Pair of Toys(解方程)

    题意:给定n个玩具要你选出两个玩具求出k的价值,第i个玩具的价值为i。若是没有选择方案,输出0

    补充:玩具A与玩具B 和 玩具B和玩具A 是同一种选择

    n,k<=1e14

    思路:列出式子,解不等式组

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<map>
     8 #include<set>
     9 #include<queue>
    10 #include<vector>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned int uint;
    14 typedef unsigned long long ull;
    15 typedef pair<int,int> PII;
    16 typedef vector<int> VI;
    17 #define fi first
    18 #define se second 
    19 #define MP make_pair
    20 #define N   210000
    21 #define MOD 1000000007
    22 #define eps 1e-8 
    23 #define pi acos(-1)
    24 #define oo 2000000000
    25 
    26 
    27 
    28 int read()
    29 { 
    30    int v=0,f=1;
    31    char c=getchar();
    32    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
    33    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
    34    return v*f;
    35 }
    36 
    37 void swap(int &x,int &y)
    38 {
    39     int t=x;x=y;y=t;
    40 }
    41 
    42 
    43 ll max(ll x,ll y)
    44 {
    45     if(x>y) return x;
    46     return y;
    47 }
    48 
    49 ll min(ll x,ll y)
    50 {
    51     if(x<y) return x;
    52     return y;
    53 }
    54 
    55 int main()
    56 {
    57 //    freopen("1.in","r",stdin);
    58 //    freopen("1.out","w",stdout);
    59     ll n,k;
    60     scanf("%lld%lld",&n,&k);
    61      ll s=max(1,max(k-n,k/2+1));
    62      ll t=min(n,k-1);
    63      if(s>t) printf("0");
    64       else 
    65       {
    66           ll ans=t-s+1;
    67         printf("%lld",ans);
    68       }
    69     
    70     return 0;
    71 }
  • 相关阅读:
    接Oracle11g_client精简版安装步骤(2019年11月18日)之Plsql配置
    Oracle11g_client精简版安装步骤(2019年11月18日)
    PC端微信版本过低问题
    Windows下Nginx无法启动且进程里没有?
    Eclipse中复制项目后,怎么更改项目名等相关配置?(2019年10月17日)
    tomcat改端口号
    java基础
    数据库
    数组相关
    Linux系统实战
  • 原文地址:https://www.cnblogs.com/myx12345/p/9843709.html
Copyright © 2011-2022 走看看