生活随笔
收集整理的這篇文章主要介紹了
2021夏季每日一题 【week3 完结】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 3554. 二進制 【難度: 簡單 / 知識點: 進制轉換】
- 3565. 完美矩陣 【難度: 一般 / 知識點: 貪心 思維】
- 3574. 乘積數量 【難度: 簡單 / 知識點: 前綴和 思維】
- 3580. 整數配對 【難度: 簡單 / 知識點: 貪心】
- 3583. 整數分組 【難度: 中 / 知識點: DP】
3554. 二進制 【難度: 簡單 / 知識點: 進制轉換】
題目詳解
#include<bits/stdc++.h>
using namespace std
;
void print(string s
,int a
)
{long long int sum
=0;for(int i
=0;i
<s
.size();i
++) {if(s
[i
]-'0') sum
=sum
*2+1;else sum
=sum
*2;}sum
=sum
+a
;string ans
;while(sum
) ans
+=to_string(sum
%2),sum
/=2;while(ans
.size()<32) ans
+="0";reverse(ans
.begin(),ans
.end());cout
<<ans
<<endl
;
}
int main(void)
{int t
; cin
>>t
;while(t
--){string s
; cin
>>s
;print(s
,1),print(s
,3);}
}
3565. 完美矩陣 【難度: 一般 / 知識點: 貪心 思維】
題目詳解
#include<bits/stdc++.h>
using namespace std
;
const int N
=210;
int a
[N
][N
],n
,m
;
int main(void)
{int t
; cin
>>t
;while(t
--){cin
>>n
>>m
;for(int i
=0;i
<n
;i
++)for(int j
=0;j
<m
;j
++)cin
>>a
[i
][j
];long long int ans
=0;for(int i
=0;i
<n
;i
++){for(int j
=0;j
<m
;j
++){vector
<int> ve(4,0);ve
[0]=a
[i
][j
],ve
[1]=a
[n
-i
-1][j
],ve
[2]=a
[i
][m
-j
-1],ve
[3]=a
[n
-i
-1][m
-j
-1];sort(ve
.begin(),ve
.end());int temp
=ve
[2];for(int k
=0;k
<4;k
++) ans
+=abs(temp
-ve
[k
]);}}cout
<<ans
/4<<endl
;}
}
3574. 乘積數量 【難度: 簡單 / 知識點: 前綴和 思維】
題目詳解
#include<bits/stdc++.h>
using namespace std
;
int main(void)
{int n
; cin
>>n
;int s
=1,l
=0,r
=1;long long int ans1
=0,ans2
=0;while(n
--){int x
; cin
>>x
;if(x
<0) s
=-s
;if(s
>0) ans1
+=l
,ans2
+=r
,r
++;else ans1
+=r
,ans2
+=l
,l
++;}cout
<<ans1
<<" "<<ans2
<<endl
;return 0;
}
3580. 整數配對 【難度: 簡單 / 知識點: 貪心】
#include<bits/stdc++.h>
using namespace std
;
const int N
=1e5+10;
int a
[N
],n
,ans
;
int main(void)
{cin
>>n
;for(int i
=0;i
<n
;i
++) cin
>>a
[i
];sort(a
,a
+n
);for(int i
=0;i
<n
;i
+=2) ans
+=a
[i
+1]-a
[i
];cout
<<ans
;return 0;
}
3583. 整數分組 【難度: 中 / 知識點: DP】
題目詳解
#include<bits/stdc++.h>
using namespace std
;
const int N
=1e5+10,M
=5010;
int f
[M
][M
],a
[N
],n
,m
;
int main(void)
{cin
>>n
>>m
;for(int i
=1;i
<=n
;i
++) cin
>>a
[i
];sort(a
+1,a
+n
+1);for(int i
=1,k
=1;i
<=n
;i
++){while(a
[i
]-a
[k
]>5) k
++;for(int j
=1;j
<=m
;j
++) f
[i
][j
]=max(f
[i
-1][j
],f
[k
-1][j
-1]+i
-k
+1);}cout
<<f
[n
][m
];return 0;
}
總結
以上是生活随笔為你收集整理的2021夏季每日一题 【week3 完结】的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。