思路:数学,思维。
对于购买
h
a
l
f
p
l
u
s
halfplus
halfplus,这种情况,一定是购买了了带小数点的情况,例如1.5,2.5,3.5这种,因为只有这种情况,才会出现赠送半个苹果,设这种情况为
x
x
x,我们逆推回去,在这种状态没有购买之前的苹果个数为
2
×
x
+
1
2\times x+1
2×x+1。
对于购买
h
a
l
f
half
half的情况,那么购买的肯定是整数个,因为不存在赠送,购买后为
x
x
x,那么逆推回购买前的状态为
2
×
x
2\times x
2×x。
#include
using namespace std;
const int N=4e6+5;
typedef long long ll;
typedef pair<ll,ll > pll;
typedef array<ll,3> p3;
int mod=998244353;
const int maxv=4e6+5;
void solve()
{
int n,p;
cin>>n>>p;
string s[n+5];
for(int i=0;i<n;i++){
string a;
cin>>a;
s[i]=a;
}
ll tot=0,sum=0;
for(int i=n-1;i>=0;i--){
if(s[i]=="halfplus"){
sum+=tot*p+p/2;
tot=tot*2+1;
}
else {
sum+=tot*p;
tot*=2;
}
}
cout<<sum<<endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
t=1;
//cin>>t;
while(t--){
solve();
}
system("pause");
return 0;
}
思路:思维。
和上一题相比,这题思维更简单,我们对题目进行一个简单的翻译,即求每一行中最小值的最大值。
#include
using namespace std;
const int N = 1e6 + 5;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef array<ll, 3> p3;
int mod = 998244353;
const int maxv = 4e6 + 5;
int a[205][205];
void solve()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
int ans=0;
for(int i=1;i<=n;i++){
int res=2e9;
for(int j=1;j<=m;j++) res=min(res,a[i][j]);
ans=max(ans,res);
}
cout<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
system("pause");
return 0;
}