首页 > 其他分享 >CV的人有福啦!YTU贪心训练2(部分注释,更新ing)

CV的人有福啦!YTU贪心训练2(部分注释,更新ing)

时间:2023-05-27 18:44:19浏览次数:47  
标签:std include int res YTU step using ing CV

------------恢复内容开始------------

无聊做了做(虽然第一题被水了)

1743 Problem A

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=100010;
 4 int n,k,s[N],a[N],sum[N],ans,x,y,res;
 5 int main()
 6 {
 7     cin>>n>>k;
 8     for(int i=0;i<n;i++) cin>>a[i];
 9     sort(a,a+n);
10     while(y<n)
11     {
12         s[x]+=a[y],sum[x]+=s[x];
13         x++,y++;
14         if(x==k) x=0;
15     }
16     for(int i=0;i<k;i++) res+=sum[i];
17     printf("%.0lf",(double)res/n);
18     return 0;
19 }

1757 Problem B

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=100010;
 4 struct node
 5 {
 6     int x,y;
 7     bool operator<(const node &w)const
 8     {
 9         return x<w.x;
10     }
11 }range[N];
12 int n,res;
13 int main()
14 {   
15     cin>>n;
16     for(int i=0;i<n;i++)
17     {
18         int a,b;
19         cin>>a>>b;if(a>b) swap(a,b);
20         range[i]={a,b};
21     }
22     sort(range,range+n);
23     int ed=range[0].r;
24     for(int i=1;i<n;i++)
25     {
26         if(range[i].x<=ed) res++;
27         else ed=range[i].y;
28     }
29     cout<<res;
30     return 0;
31 }

1002 Problem C

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=100010;
 4 int n,m;
 5 double res;
 6 struct node
 7 {
 8     double t,v,x;
 9     bool operator<(const node &w)const
10     {
11         return x>w.x;
12     }
13 }f[N];
14 int main()
15 {
16     while(cin>>n>>m&&n!=0)
17     {
18         memset(f,0,sizeof f);
19         res=0;
20         for(int i=1;i<=n;i++) cin>>f[i].t>>f[i].v,f[i].x=f[i].v/f[i].t;
21         sort(f+1,f+n+1);
22         for(int i=1;i<=n;i++)
23         {
24             if(m-f[i].t<0)
25             {
26                 res+=f[i].x*(double)m;
27                 break;
28             }
29             else m-=f[i].t,res+=(double)f[i].v;
30         }
31         printf("%.2lf\n",res);
32     }
33     return 0;
34 }

2461 Problem D

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=100;
 4 int n,a[5]={1,3,9,27,81},f[N];
 5 string s;
 6 bool vis;
 7 void dfs(int st,int t,int num,int step)
 8 {
 9     if(vis) return;
10     if(num==t)
11     {
12         for(int i=0;i<step+1;i++)
13         {
14             if(i<step) cout<<f[i]<<s[i];
15             else cout<<f[i];
16         }
17         vis=true;
18     }
19     if(num>t) for(int i=st-1;i>=0;i--)
20     {
21         f[step+1]=a[i],s[step]='-';
22         dfs(i,t,num-a[i],step+1);
23         f[step+1]=0;
24     }
25     else for(int i=st-1;i>=0;i--)
26     {
27         f[step+1]=a[i],s[step]='+';
28         dfs(i,t,num+a[i],step+1);
29         f[step+1]=0;
30     }
31     return;
32 }
33 int main()
34 {
35     cin>>n;
36     int p;
37     if(n<=81)
38     {for(int i=0;i<5;i++) if(a[i]>=n){p=i;break;}}
39     else p=4;
40     f[0]=a[p];
41     dfs(p,n,a[p],0);
42     return 0;
43 }
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=100000;
 4 int n,k,res,a[5]={1,3,9,27,81};
 5 int main()
 6 {
 7     cin>>n;
 8     if(n<=81)
 9     {for(int i=0;i<5;i++) if(a[i]>=n) {k=i;break;}}//找到最接近的
10     else k=4;
11     res=a[k];
12     cout<<a[k];
13     int num=0;
14     while(res!=n)
15     {
16         int x,c;
17         for(int i=0;i<4;i++)
18             if(a[i]<=abs(n-res)&&a[i+1]>=abs(n-res)) {x=i;break;}//找到处于这之间的
19         if(abs(a[x]-res+n)>abs(a[x+1]-res+n)) c=x+1;//找到最接近的那个
20         else c=x;
21         if(res>n) cout<<'-'<<a[c],res-=a[c];//判断
22         else cout<<'+'<<a[c],res+=a[c];
23     }
24     return 0;
25 }

3155 Problem I

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int a,b,c,d,e,f,res;
 4 int op[4]={0,5,3,1};
 5 int main()
 6 {
 7     while(cin>>a>>b>>c>>d>>e>>f&&(a+b+c+d+e+f)!=0)
 8     {
 9         res=f+d+e+(c+3)/4;
10         int x=d*5+op[c%4];//先算2x2的箱子
11         if(b>x) res+=(b-x+8)/9;
12         int y=36*res-36*f-25*e-16*d-9*c-4*b;
13         if(a>y) res+=(a-y+35)/36;
14         cout<<res<<endl;
15     }
16     return 0;
17 }

 

标签:std,include,int,res,YTU,step,using,ing,CV
From: https://www.cnblogs.com/o-Sakurajimamai-o/p/17437151.html

相关文章

  • java——微服务——spring cloud——Eureka——插叙——服务访问——Demo——示例演示
                 user查询:             order订单查询:            user服务,查询user对象:            查询order对象:            ......
  • Basics of Neural Network Programming
    目录BasicsofNeuralNetworkProgrammingLogisticRegressionBasicsofNeuralNetworkProgrammingLogisticRegressiongivenx,want\(\hat{y}=P(y=1|x)\),\(x\in\R^{n_x}\)\(\hat{y_1}=w_{11}*x_{11}+w_{12}*x_{12}+\dots+w_{1n_x}*x_{1n_x}+b_1\).P......
  • Springboot——参数校验
    springboot参数校验注解在controller层需要对前端传来的参数进行校验校验简单数据类型使用springboot自带的validation工具可以从后端对前端传来的数据进行校验使用方法:创建项目时引入I/O场景下的validation起步依赖使用maven创建项目时,引入起步依赖:<depen......
  • 重塑Windows!微软王炸更新:操作系统全面接入ChatGPT,Bing也能用插件了
    一夜之间,微软彻底重新定义了PC交互。因为这一次,它把Bing和ChatGPT插件的能力,注入到了整个Windows系统!这就是在刚刚结束的Build2023中,微软重磅推出的WindowsCopilot。有了它,想让自己的PC变得更适合工作,就只需要一个简单的动作——问:如何调整我的系统,(以便更好地)来完成工作?然后Windo......
  • 【深入浅出Spring原理及实战】「缓存Cache开发系列」带你深入分析Spring所提供的缓存C
    缓存的理解缓存的工作机制是先从缓存中读取数据,如果没有再从慢速设备上读取实际数据,并将数据存入缓存中。通常情况下,我们会将那些经常读取且不经常修改的数据或昂贵(CPU/IO)的且对于相同请求有相同计算结果的数据存储到缓存中。它能够让数据更加接近于使用者,下图所示。+-------------......
  • 未授权访问漏洞检测工具(CVE-2023-29922)
    ===================================免责声明请勿利用文章内的相关技术从事非法测试,由于传播、利用此文所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,作者不为此承担任何责任。工具来自网络,安全性自测,如有侵权请联系删除。0x01工具介绍PowerJob<=4.3.2......
  • java——微服务——spring cloud——Eureka——服务注册
           2步搞定:1、引入依赖    2、编写配置 user服务:           order服务:一样的处理                                        ......
  • java——微服务——spring cloud——Eureka——搭建Eureka服务
        创建新工程:    创建main函数,并添加注解      编写参数:     启动:     点击打开浏览器:              ......
  • Springboot+Guava实现单机令牌桶限流
    令牌桶算法系统会维护一个令牌(token)桶,以一个恒定的速度往桶里放入令牌(token),这时如果有请求进来想要被处理,则需要先从桶里获取一个令牌(token),当桶里没有令牌(token)可取时,则该请求将被拒绝服务。令牌桶算法通过控制桶的容量、发放令牌的速率,来达到对请求的限制。=================......
  • [ICDE 2023] Minimizing the Influence of Misinformation via Vertex Blocking
    MinimizingtheInfluenceofMisinformationviaVertexBlockingMotivationandApplication其实就是经典的RumorBlocking问题,即通过一系列的操作使得rumor在社交网络中的影响力最小。主流的方法有三种:找到一组seedset去和rumor节点竞争,社交网络中的节点都只能被激活一次,......