2019年湖南科技大學第7屆大學生計算機程式設計競賽A~D
阿新 • • 發佈:2020-12-16
話不多說,直接上程式碼吧,希望能給大家一些思路上的幫助QAQ
A:下雨天
思路:模擬
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
using namespace std;
//head file
int main()
{
string s;
cin>>s;
int cnt=0;
rep(i,0,s.size()-1)
{
if(s[i]=='R'&&s[i+ 1]=='R')
cnt++;
}
cout<<cnt<<endl;
}
B:輕鬆籌
思路:找規律後,暴力去找。
#include<bits/stdc++.h>
#define ll long long
//#define int long long
#define rep(i,a,n) for (int i=a;i<n;i++)
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
//head file
int main()
{
ll n;
while(cin>>n)
{
int i;
for(i=1;;i++)
{
if(n>=qpow(2,i-1)&&n<qpow(2,i))
{
break;
}
}
cout<<i<<endl;
}
}
C: 萬物皆可盤
思路:還是找規律,發現當袋子依次為2的冪次時,可以最節約袋子數量,然後多出來的硬幣,裝在一個袋子裡
#include<bits/stdc++.h>
#define ll long long
//#define int long long
#define rep(i,a,n) for (int i=a;i<n;i++)
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
using namespace std;
//head file
int main()
{
ll n;
while(cin>>n)
{
int cnt=0;
for(ll i=0;;i++)
{
if(n<=qpow(2,i))
{
cnt++;
break;
}
else
{
n-=qpow(2,i);
cnt++;
}
}
cout<<cnt<<endl;
}
}
D:翻天
思路:用兩個陣列來模擬翻天前和翻天后的列高,然後從左到右遍歷一遍,如果有翻不過去的,就翻天一次,其他的情況肯定是翻的過去的。
#include<bits/stdc++.h>
#define eps 1e-6
#define ll long long
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define int long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define fi first
#define se second
#define endl "\n"
#define pii pair<int,int>
#define fi first
#define se second
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll Max(ll a,ll b){return a>=b?a:b;}
ll Min(ll a,ll b){return a<=b?a:b;}
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res,t;res=1;t=a%c;while(b){if(b&1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
//head file
char a[200][200];
int tian[200];
int di[200];
int main()
{
int t;
cin>>t;
for(int k=1;k<=t;k++)
{
int r,c,d;
int fan=0;
cin>>r>>c>>d;
rep(i,0,r)
{
rep(j,0,c)
{
cin>>a[i][j];
}
getchar();
}
rep(j,0,c)
{
int cnt=0;
rep(i,0,r)
{
if(a[i][j]=='#')
cnt++;
}
tian[j]=cnt;
di[j]=r-cnt;
}
int flag=1;
for(int i=0;i+1<c;i++)
{
if(flag==1)
{
if(tian[i+1]-tian[i]>d)
{
flag=0;
fan++;
}
}
if(flag==0)
{
if(di[i+1]-di[i]>d)
{
flag=1;
fan++;
}
}
}
cout<<"Case "<<k<<": "<<fan<<endl;
}
}
暫時就更到ABCD啦。才不是因為後面寫不出了
之後會慢慢更,當作對自己ACM知識補充的記錄啦,為校賽做好準備。