A题:
判断>2的偶数;
B题:(回溯)
#include <iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#include<cctype>
using namespace std;
int days,times;
int xt1[1000],xt2[1000];
int sum,i,j,k;
int a[1000];
int main()
{
cin>>days>>times;
for(i=1;i<=days;i++)
{
cin>>xt1[i]>>xt2[i];
}
for(i=1;i<=days;i++)
a[i]=xt1[i];
while(1)
{
sum=0;
for(i=1;i<=days;i++)
sum+=a[i];
if(sum==times)
{
cout<<"YES"<<endl;
for(i=1;i<=days;i++)
cout<<a[i]<<' ';
cout<<endl;
break;
}
i=1;
while(a[i]==xt2[i]&&i<=days)i++;
if(i>days)
{
cout<<"NO"<<endl;
break;
}
a[i]++;
}
}
C题:(模拟)
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<stack>
#include<algorithm>
using namespace std;
int n,i,j,k;
string a[100001];
string str;
int b[100001];
int main()
{
cin>>n;
memset(b,0,sizeof(b));
int k=1;
for(i=1;i<=n;i++)
{
cin>>a[k];
getchar();
int gs=1;
for(j=1;j<k;j++)
{
if(a[k]==a[j])//重复不存
{
gs=0;
b[j]++;//标记数组
str=a[k];
a[k]="";
break;
}
}
if(gs==0)
cout<<str<<b[j]<<endl;
else
{
cout<<"OK"<<endl;
k++;
}
}
return 0;
}
D题:(动态规划)
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<stack>
#include<algorithm>
using namespace std;
int n,wi,hi;
struct node
{
int w;
int h;
int fs;//标记位置
}wh[6005];
int i,j,kl,k;
int dp[6001];
int sum[6001];
int a[6001];
bool cmp(node a,node b)
{
if(a.w<b.w)
return true;
if(a.w>b.w)
return false;
if(a.w==b.w)
{
if(a.h<b.h)
return true;
if(a.h>=b.h)
return false;
}
}
int main()
{
cin>>n>>wi>>hi;
k=1;
for(i=1;i<=n;i++)
{
cin>>wh[k].w>>wh[k].h;
if(wh[k].w>wi&&wh[k].h>hi)(切掉不满足条件的)
{
wh[k].fs=i;
k++;
}
}
if(k==1&&(wh[1].w<=wi||wh[1].h<=hi))
{
cout<<'0'<<endl;
return 0;
}
//for(i=1;i<k;i++)
// cout<<wh[i].w<<' '<<wh[i].h<<' '<<wh[i].fs<<endl;
sort(wh+1,wh+k,cmp);
memset(dp,0,sizeof(dp));
for(i=1;i<k;i++)
{
for(j=1;j<i;j++)
{
if(wh[i].w>wh[j].w&&wh[i].h>wh[j].h)
if(dp[i]<dp[j]+1)
{
dp[i]=dp[j]+1;
sum[i]=j;//记录路径,把前后路径接在一起
}
}
}
int max1=-1,max0;
for(i=1;i<k;i++)//再次扫描
{
if(max1<dp[i])
{
max1=dp[i];
max0=i;
}
}
cout<<max1+1<<endl;//由于刚开始为0,最后要加1
i=max0;
int ks=0;
while(1)
{
a[ks++]=wh[i].fs;//数组a转移地址
i=sum[i];
if(i<=0)
break;
}
for(i=ks-1;i>=0;i–)//输出地址fs
cout<<a[i]<<' ';
cout<<endl;
return 0;
}
E题:
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<cctype>
#include<queue>
#include<vector>
using namespace std;
int a[5];
int i,j;
int main()
{
for(i=1;i<=4;i++)
cin>>a[i];
int glag[5]={0};//标记数组
//判断
if(abs(a[1]-a[2])<a[3]&&(a[1]+a[2])>a[3])
glag[1]=1;
if((a[1]+a[2])==a[3]||(a[1]+a[3])==a[2]||(a[2]+a[3])==a[1])glag[1]=2;
if(abs(a[1]-a[2])<a[4]&&(a[1]+a[2])>a[4])
glag[2]=1;
if((a[1]+a[2])==a[4]||(a[1]+a[4])==a[2]||(a[2]+a[4])==a[1])glag[2]=2;
if(abs(a[1]-a[4])<a[3]&&(a[1]+a[4])>a[3])
glag[3]=1;
if((a[1]+a[4])==a[3]||(a[1]+a[3])==a[4]||(a[4]+a[3])==a[1])glag[3]=2;
if(abs(a[4]-a[2])<a[3]&&(a[4]+a[2])>a[3])
glag[4]=1;
if((a[4]+a[2])==a[3]||(a[4]+a[3])==a[2]||(a[2]+a[3])==a[4])glag[4]=2;
int gs1=0;
int gs2=0;
int gs0=0;
for(i=1;i<=4;i++)//输出结果
{
if(glag[i]==1)
{
cout<<"TRIANGLE"<<endl;
gs1=1;
break;
}
if(glag[i]==2)
{
gs2=1;
}
}
if(gs2==1&&gs1==0)
cout<<"SEGMENT"<<endl;
if(gs2==0&&gs1==0)
cout<<"IMPOSSIBLE"<<endl;
return 0;
}
F题:
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<stack>
#include<algorithm>
using namespace std;
int n,m,i,j;
char c;
char str[1000][1000];
int sum[1000]={0};
int main()
{
cin>>n>>m;
getchar();
cin>>c;
int k=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>str[i][j];
}
getchar();
}
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
if(str[i][j]==c)
{
if(isupper(str[i][j+1])&&(j+1)<=m)
{
int mc=str[i][j+1]-'A';
sum[mc]++;//标记
}
if(isupper(str[i][j-1])&&(j-1)>=1)
{
int mc=str[i][j-1]-'A';
sum[mc]++;
}
if(isupper(str[i+1][j])&&(i+1)<=n)
{
int mc=str[i+1][j]-'A';
sum[mc]++;
}
if(isupper(str[i-1][j])&&(i-1)>=1)
{
int mc=str[i-1][j]-'A';
sum[mc]++;
}
}
}
int s=0;
for(i=0;i<26;i++)
{
if(sum[i]&&i!=c-'A')
s++;
}
cout<<s<<endl;
return 0;
}
G题:
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<cctype>
#include<queue>
#include<vector>
using namespace std;
long a[100005];
int i,j,n;
long sum1;
long sum2;
long sum,p,q;
int ans1,ans2;
int main()
{
cin>>n;
sum=0;
for(i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
}
p=1;q=n;//指针标记
sum1=0;//记录所吃的量
sum2=0;
ans1=0;//记录块数
ans2=0;
while(p<=q)
{
while(p<=q&&sum1<=sum2)
{
sum1+=a[p];
p++;
ans1++;
}
while(p<=q&&sum1>sum2)
{
sum2+=a[q];
q--;
ans2++;
}
}
//cout<<p<<' '<<q<<endl;
//cout<<sum1<<' '<<sum2<<endl;
cout<<ans1<<' '<<ans2<<endl;
return 0;
}
转载于:https://www.cnblogs.com/sdau–codeants/p/3234151.html