一共五道代码题,分别为《开锁》《勇闯币圈》《迎宾车队》《水站的水流量》前四道全a,cpp代码如下,第五题实在写不出来只能a10%,求指导
第一题
//开锁
/*input
1 2
1 100
2 4
347 177 40 84
107 282 347 193
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
char c = getchar(); ll x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
std::vector<int> v[maxn];;
int main(){
int n=read(), m=read();
double ans=0.0;
for(int j=0;j<n;j++){
for(int t,i=0;i<m;i++){
t=read();
v[i].push_back(t);
}
}
for(int i=0;i<m;i++){
sort(v[i].begin(),v[i].end());
for(int j=1;j<v[i].size();j++){
v[i][j]+=v[i][j-1];
}
}
for(int i=0;i<m;i++){
for(int j=1;j<=n;j++){
ans+=1.0/(j)*v[i][j-1];
}
}
printf("%.8f ",ans);
return 0;
}
第二题
//勇闯币圈
/*input
3
0
0 0 1
0.4 0.2 0.4
0.2 0.1 0.7
0.3 0.5 0.2
0.5 0.4 0.1
2
0.4 0.2 0.4
0.2 0.1 0.7
0.3 0.5 0.2
0.5 0.4 0.1
10
0.4 0.2 0.4
0.2 0.1 0.7
0.3 0.5 0.2
0.5 0.4 0.1
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
char c = getchar(); ll x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
double sta[3][3];
int main(){
int T=read();
while(T--){
int t=read();
double cur0, cur1, cur2, l0, l1, l2;
cin>>l0>>l1>>l2;//稳定、跌、涨
cur0=l0, cur1=l1, cur2=l2;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
cin>>sta[j][i];
for(int i=0;i<t;i++){
cur0=l0*sta[0][0]+l1*sta[1][0]+l2*sta[2][0];
cur1=l0*sta[0][1]+l1*sta[1][1]+l2*sta[2][1];
cur2=l0*sta[0][2]+l1*sta[1][2]+l2*sta[2][2];
l0=cur0, l1=cur1, l2=cur2;
}
if(cur2>0.5) puts("1");
else puts("0");
}
return 0;
}
第三题
//迎宾车队
/*input
7
1 2 3 44 45 46 47
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
char c = getchar(); ll x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
int a[maxn];
int main(){
int n=read();
for(int i=0;i<n;i++){
a[i]=read();
}
sort(a,a+n);
int ans=0;
int idx=0;
for(int i=0;i<n;i++){
while(a[idx]-a[i]<=10&&idx<n) idx++;
ans=max(ans,idx-i);
}
cout<<ans<<endl;
return 0;
}
第四题
//水站的水流量
/*input
3 1000
3 5
2 2
3 4
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
char c = getchar(); ll x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
std::vector<int> G[maxn];
int a[maxn];
void dfs(int u, int fa, int cur){
//cout<<u<<' '<<fa<<' '<<cur<<endl;
if(cur<=0) return;
if(G[u].size()==0) {
a[u]+=cur;
return;
}
if(a[u]<1024){
if(a[u]+cur>=1024){
cur=cur-(1024-a[u]);
a[u]=1024;
for(auto v:G[u]) dfs(v,u,cur/2);
}
else a[u]+=cur;
}
else{
for(auto v:G[u]) dfs(v,u,cur/2);
}
}
int main(){
int n=read(), t=read();
for(int i=0;i<n-1;i++){
for(int u=1+i*(1+i)/2;u<=1+i*(1+i)/2+i;u++){
int v1=u+i+1;
int v2=u+i+2;
G[u].push_back(v1);
G[u].push_back(v2);
//cout<<u<<' '<<v1<<' '<<v2<<endl;
}
}
while(t--){
dfs(1,0,1024);
}
int num=0;
for(int i=1;i<maxn;i++){
if(a[i]>=1024) num++;//, cout<<i<<endl;
}
cout<<num<<endl;
return 0;
}
/*input
1 2
1 100
2 4
347 177 40 84
107 282 347 193
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
char c = getchar(); ll x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
std::vector<int> v[maxn];;
int main(){
int n=read(), m=read();
double ans=0.0;
for(int j=0;j<n;j++){
for(int t,i=0;i<m;i++){
t=read();
v[i].push_back(t);
}
}
for(int i=0;i<m;i++){
sort(v[i].begin(),v[i].end());
for(int j=1;j<v[i].size();j++){
v[i][j]+=v[i][j-1];
}
}
for(int i=0;i<m;i++){
for(int j=1;j<=n;j++){
ans+=1.0/(j)*v[i][j-1];
}
}
printf("%.8f ",ans);
return 0;
}
第二题
//勇闯币圈
/*input
3
0
0 0 1
0.4 0.2 0.4
0.2 0.1 0.7
0.3 0.5 0.2
0.5 0.4 0.1
2
0.4 0.2 0.4
0.2 0.1 0.7
0.3 0.5 0.2
0.5 0.4 0.1
10
0.4 0.2 0.4
0.2 0.1 0.7
0.3 0.5 0.2
0.5 0.4 0.1
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
char c = getchar(); ll x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
double sta[3][3];
int main(){
int T=read();
while(T--){
int t=read();
double cur0, cur1, cur2, l0, l1, l2;
cin>>l0>>l1>>l2;//稳定、跌、涨
cur0=l0, cur1=l1, cur2=l2;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
cin>>sta[j][i];
for(int i=0;i<t;i++){
cur0=l0*sta[0][0]+l1*sta[1][0]+l2*sta[2][0];
cur1=l0*sta[0][1]+l1*sta[1][1]+l2*sta[2][1];
cur2=l0*sta[0][2]+l1*sta[1][2]+l2*sta[2][2];
l0=cur0, l1=cur1, l2=cur2;
}
if(cur2>0.5) puts("1");
else puts("0");
}
return 0;
}
第三题
//迎宾车队
/*input
7
1 2 3 44 45 46 47
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
char c = getchar(); ll x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
int a[maxn];
int main(){
int n=read();
for(int i=0;i<n;i++){
a[i]=read();
}
sort(a,a+n);
int ans=0;
int idx=0;
for(int i=0;i<n;i++){
while(a[idx]-a[i]<=10&&idx<n) idx++;
ans=max(ans,idx-i);
}
cout<<ans<<endl;
return 0;
}
第四题
//水站的水流量
/*input
3 1000
3 5
2 2
3 4
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
char c = getchar(); ll x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int inf=0x3f3f3f3f;
const int maxn=1e5+50;
std::vector<int> G[maxn];
int a[maxn];
void dfs(int u, int fa, int cur){
//cout<<u<<' '<<fa<<' '<<cur<<endl;
if(cur<=0) return;
if(G[u].size()==0) {
a[u]+=cur;
return;
}
if(a[u]<1024){
if(a[u]+cur>=1024){
cur=cur-(1024-a[u]);
a[u]=1024;
for(auto v:G[u]) dfs(v,u,cur/2);
}
else a[u]+=cur;
}
else{
for(auto v:G[u]) dfs(v,u,cur/2);
}
}
int main(){
int n=read(), t=read();
for(int i=0;i<n-1;i++){
for(int u=1+i*(1+i)/2;u<=1+i*(1+i)/2+i;u++){
int v1=u+i+1;
int v2=u+i+2;
G[u].push_back(v1);
G[u].push_back(v2);
//cout<<u<<' '<<v1<<' '<<v2<<endl;
}
}
while(t--){
dfs(1,0,1024);
}
int num=0;
for(int i=1;i<maxn;i++){
if(a[i]>=1024) num++;//, cout<<i<<endl;
}
cout<<num<<endl;
return 0;
}
全部评论
(2) 回帖