这里写目录标题
11-1
#include<iostream>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
double money=200.0;
int sum = 0;
for(int i=1;i<=20;i++)
{
if(i>=2)
money = money * (1+k/(100*1.0));
sum += n;
if(sum >= money)
{
cout<<i<<endl;
return 0;
}
}
cout<<"Impossible"<<endl;
return 0;
}
11-2
Input
Output
输出仅有一行,该行只有一个整数,如题所示。
Sample Input
4
0 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 0
Sample Output
1
代码
#include<iostream>
using namespace std;
const int N = 21;
int n, a[N][N], b[N][N], c[N][N];
bool same()
{
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (a[i][j] != c[i][j])
return 0;
return 1;
}
void turn()
{
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
b[i][j] = a[n - j + 1][i];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
a[i][j] = b[i][j];
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> a[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> c[i][j];
for(int i=0;i<=3;i++)
{
if (same())
{
cout << i << endl;
return 0;
}
turn();
}
cout << "-1" << endl;
return 0;
}
11-3
#include<iostream>
using namespace std;
int main()
{
string s;
while(cin>>s)
{
for(int i=0;i<s.size();i++)
{
if(s[i]>=65&&s[i]<=90)
{
s[i] = s[i] - 5;
if(s[i]<65)
s[i] = s[i] + 26;
}
}
cout<<s<<" ";
}
return 0;
}
11-4
Input
输入:
第一行:一个整数n(2≤n≤100000),寿司序列的长度。
第二行:n个整数(每个整数不是1就是2,意义如上所述)
Output
输出:一个整数(代表东东可以选择的最长的一段连续的且合法的寿司)
Sample Input-1
7
2 2 2 1 1 2 2
Sample Output-1
4
Sample Input-2
6
1 2 1 2 1 2
Sample Output-2
2
Sample Input-3
9
2 2 1 1 1 2 2 2 2
Sample Output-3
6
解题思路以及关键代码
以样例2 2 1 1 1 2 2 2 2来看,a[i]存的是输入的数据,维护一个b[i]存的是一段
连续的数字的个数,b[1]=2,b[2]=3,b[3]=4;
ans=max(ans,2*min(b[i],b[i-1]));
所以 ans = 3*2 = 6;
全部代码
#include <iostream>
using namespace std;
const int N=100000+5;
int n,a[N],b[N];
int count=0;
int solve()
{
int temp=a[0];
for(int i=0;i<n;i++)
{
if(a[i]==temp)
b[count]++;
else
{
b[++count]=1;
temp=a[i];
}
}
int ans=0;
for(int i=1;i<=count;i++)
{
ans=max(ans,2*min(b[i],b[i-1]));
}
return ans;
}
int main()
{
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
int ans=solve();
cout<<ans<<endl;
return 0;
}