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
*/