国庆7天乐(相遇)

10.1 个人赛

c1 A - Creating a Character CodeForces - 1217A 思维

传送门
题目大意:三个数a,b,c,问有多少种差分c的方案,使a始终大于b。
思路:
数据很大,暴力肯定T。数学公式推导,推导如下
设x为两边同时加上的数,且保证A>B,所以 a+x>b+c-x
x>(b+c-a)/2
需要注意的是,如果b+c-a小于零,则a可以从0加起走

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include<time.h>
#include <stack>
#include <list>
#include <set>
#include <sstream>
#include <iterator>
using namespace std;
#define ll long long int
#define fro(i,a,n) for(ll i=a;i<n;i++)
#define pre(i,a,n) for(ll i=n-1;i>=a;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define fi first
#define se second
#define s_d(a) scanf("%d",&a)
#define s_lld(a) scanf("%lld",&a)
#define s_s(a) scanf("%s",a)
#define s_ch(a) scanf("%c",&a)
typedef pair<ll,ll> P;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
const double PI = 3.1415926535897932;
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
const int maxn = 1e6+10;
int lowbit(int x){return x&(-x);}

int main()
{
    ios::sync_with_stdio(0);
    int t;
    cin>>t;
    fro(i,0,t)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        int sum=0;
        if(!c)
        {
            if(a>b)
            cout<<1<<endl;
            else
            cout<<0<<endl;
        }
        else
        {
            int sum2=b+c-a;
           // int mina;
            if(sum2<0)
                sum2=0;
            else
            {
                sum2=sum2/2+1;//保证向上求余
            }
            int maxa=c;
            cout<<max(maxa-sum2+1,0)<<endl;;
        }
    }
    return 0;
}

C1 B - Zmei Gorynich CodeForces - 1217B 贪心

传送门
题目大意:题意:一条龙m个头,你有n种砍法,每种可以砍下a个头,但是重新会长出b个头,问最少多少次可以杀死它,不能杀死输出-1.。
思路:自己做的时候想得很复杂,贪心方案选的是一刀平均能砍下头的来排序的,实际上并不是。实际上,这道题最优砍法就是(n-a)最大就行,另外,你可以选出最大的伤害,可以最后一刀秒的那种
所以思路就是选出最大伤害,和最优砍法,先最大伤害砍一刀,最后进行除余判断,输出。

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include<time.h>
#include <stack>
#include <list>
#include <set>
#include <sstream>
#include <iterator>
using namespace std;
#define ll long long int
#define fro(i,a,n) for(ll i=a;i<n;i++)
#define pre(i,a,n) for(ll i=n-1;i>=a;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define fi first
#define se second
#define s_d(a) scanf("%d",&a)
#define s_lld(a) scanf("%lld",&a)
#define s_s(a) scanf("%s",a)
#define s_ch(a) scanf("%c",&a)
typedef pair<ll,ll> P;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
const double PI = 3.1415926535897932;
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
const int maxn = 1e3+10;
int lowbit(int x){return x&(-x);}
int main()
{
   ios::sync_with_stdio(0);
   int t;
   cin>>t;

   while(t--)
   {
       int maxa=-INF,maxd=-INF;
       int n,m;
       cin>>n>>m;
       bool ok=0;
       fro(i,0,n)
       {
           int d,h;
           cin>>d>>h;
           if(d>=m)
            ok=1;
           maxa=max(d,maxa);
           maxd=max(maxd,d-h);
       }
       if(ok)
        cout<<1<<endl;
       else if(maxd<=0)
        cout<<-1<<endl;
        else
       {
        m-=maxa;
       if(m<=0)
        cout<<1<<endl;
       else
       {
           if(m%maxd==0)
            cout<<m/maxd+1<<endl;
           else
            {
                cout<<m/maxd+2<<endl;
            }
       }
       }

   }
    return 0;
}
/*
3
3 10
6 3
8 2
1 4
4 10
4 1
3 2
2 6
1 100
2 15
10 11
14 100

2
3
-1
*/

A - Optimal Currency Exchange CodeForces - 1214A 思维

传送门
题目大意:见原题

思路:美元的面值都是1的倍数,欧元的面值都是5的倍数,每次枚举最小的就行,直到不能再分,即最小

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include<time.h>
#include <stack>
#include <list>
#include <set>
#include <sstream>
#include <iterator>
using namespace std;
#define ll long long int
#define fro(i,a,n) for(ll i=a;i<n;i++)
#define pre(i,a,n) for(ll i=n-1;i>=a;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define fi first
#define se second
#define s_d(a) scanf("%d",&a)
#define s_lld(a) scanf("%lld",&a)
#define s_s(a) scanf("%s",a)
#define s_ch(a) scanf("%c",&a)
typedef pair<ll,ll> P;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
const double PI = 3.1415926535897932;
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
 int maxn = 1e9+10;
int lowbit(int x){return x&(-x);}
int dollor[7]={1,2,5,10,20,50,100};
int euro[6]={5,10,20,50,100,200};
int main() {
	int n,d,e;
	cin>>n>>d>>e;

    euro[0]*=e;
    dollor[0]*=d;
    int i=0;
    while(i<=n)
	{
	    int a=(n-i)%dollor[0];
		maxn =min(maxn,a);
		i+=euro[0];
	}
	cout<<maxn<<endl;
	return 0;
}

D - Treasure Island CodeForces - 1214D 思维+dfs

传送门
题目大意:一张图有许多障碍物,你最少能添加几个障碍物时那个人不能到达终点。

思路:从起点dfs一次到终点,如果不能到达,输出0,如果可以到达,标记路径,在一次dfs,如果不能到达输出1,如果还能到达输出2。

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include<time.h>
#include <stack>
#include <list>
#include <set>
#include <sstream>
#include <iterator>
using namespace std;
#define ll long long int
#define fro(i,a,n) for(ll i=a;i<n;i++)
#define pre(i,a,n) for(ll i=n-1;i>=a;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define fi first
#define se second
#define s_d(a) scanf("%d",&a)
#define s_lld(a) scanf("%lld",&a)
#define s_s(a) scanf("%s",a)
#define s_ch(a) scanf("%c",&a)
typedef pair<ll,ll> P;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
const double PI = 3.1415926535897932;
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
const int maxn = 1e6+10;
string s[maxn];
int lowbit(int x){return x&(-x);}
map<P,int> mp;
int m,n;
int dir[2][2]={{1,0},{0,1}};
bool dfs(int a,int b)
{
    if(a==n-1&&b==m-1)
    {
        return true;
    }
    fro(i,0,2)
    {
        int aa=a+dir[i][0];
        int bb=b+dir[i][1];
        if(aa>=n||aa<0||bb>=m||bb<0||mp[make_pair(aa,bb)]==1||s[aa][bb]=='#')
            continue;
            bool ok=0;
        if(aa==n-1&&bb==m-1)
        {
            ok=1;
        }
        if(!ok)
        mp[make_pair(aa,bb)]=1;
        //cout<<mp[make_pair(aa,bb)]<<endl;
        if(dfs(aa,bb))
            return true;
        //mp[make_pair(aa,bb)]=0;
    }
    return false;
}
int main()
{
    ios::sync_with_stdio(0);
   cin>>n>>m;
    fro(i,0,n)
    {
        cin>>s[i];
    }
    if(!dfs(0,0))
        {cout<<0<<endl;return 0;}
    if(!dfs(0,0))
        {cout<<1<<endl;return 0;}
    cout<<2<<endl;
    return 0;
}
/*f
2 2
..
..

2
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值