首页 > 其他分享 >8.5做题记录

8.5做题记录

时间:2023-08-05 17:11:06浏览次数:38  
标签:std 8.5 记录 int 20 做题 freopen using return

上午

 1 #include <bits/stdc++.h>
 2 #define int long long
 3 using namespace std;
 4 int ans[20],s;
 5 signed main()
 6 {
 7     freopen("x3.in","r",stdin);
 8     freopen("x3.out","w",stdout);
 9     int n,l,maxn=-1;
10     cin>>n;
11     for(int i=1;i<=n;i++)
12     {
13         int x;
14         cin>>x;
15         l=0;
16         while(x)
17         {
18             l++;
19             if(x&1)
20                 ans[l]++;
21             x>>=1;
22         }
23         maxn=max(maxn,l);
24     }
25     for(int i=1;i<=maxn;i++)
26         s+=(1<<(i-1))*ans[i]*(n-ans[i]);
27     cout<<s;
28     return 0;
29 }

 1 //40pts
 2 #include <bits/stdc++.h>
 3 using namespace std;
 4 int n,m,a[500005],zx[500005];
 5 vector < int > v[500005];
 6 int main()
 7 {
 8     freopen("place.in","r",stdin);
 9     freopen("place.out","w",stdout);
10     zx[1]=1;
11     cin>>n>>m>>a[1];
12     for(int i=2;i<=n;i++)
13         v[1].push_back(i);
14     for(int i=2;i<=n;i++)
15     {
16         int x;
17         cin>>a[i]>>x;
18         zx[i]=x;
19         int p=x;
20         while(zx[p]!=p)
21         {
22             v[p].push_back(i);
23             p=zx[p];
24         }
25     }
26     /*for(int i=1;i<=n;i++)
27     {
28         cout<<zx[i]<<endl;
29         for(int j=0;j<v[i].size();j++)
30             cout<<
31     }*/
32     while(m--)
33     {
34         char c;
35         cin>>c;
36         if(c=='p')
37         {
38             int x,y;
39             cin>>x>>y;
40             for(int i=0;i<v[x].size();i++)
41                 a[v[x][i]]+=y;
42         }
43         else
44         {
45             int x;
46             cin>>x;
47             cout<<a[x]<<endl;
48         }
49     }
50     return 0;
51 }

 1 #include <bits/stdc++.h>
 2 #define int long long
 3 #define N 1000000000
 4 using namespace std;
 5 int n,ss[1000005],t,b,k=1,p,l,r,mid;
 6 bool bz[100005];
 7 void dfs(int x,int s,int h)
 8 {
 9     if(x==t || s*ss[x]>mid)
10     {
11         if(h&1)
12             b+=mid/s;
13         else b-=mid/s;
14         return;
15     }
16     if(s*ss[x]<=mid)
17         dfs(x+1,s*ss[x],h+1);
18     dfs(x+1,s,h);
19 }
20 signed main()
21 {
22     freopen("broj.in","r",stdin);
23     freopen("broj.out","w",stdout);
24     cin>>n>>p;
25     if(n==1)
26     {
27         cout<<p;
28         return 0;
29     }
30     else if(p*p>N)
31     {
32         cout<<0;
33         return 0;
34     }
35     for(int i=2;i<=p;i++)
36     {
37         if(!bz[i])
38             ss[++t]=i;
39         for(int j=1;j<=t;j++)
40         {
41             if(i*ss[j]>p)
42                 break;
43             bz[i*ss[j]]=1;
44             if(i%ss[j]==0)
45                 break;
46         }
47     }
48     l=p,r=N/p+1;
49     while(l<=r)
50     {
51         mid=l+r>>1;
52         b=mid,dfs(1,1,0);
53         b=mid-b;
54         if (b<n) l=mid+1;
55         else r=mid-1;
56     }
57     if (l*p>N)
58         cout<<0;
59     else
60         cout<<l*p;
61     return 0;
62 }

下午

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 char a[105][105],s; 
 4 int main()
 5 {
 6     freopen("puzzle.in","r",stdin);
 7     freopen("puzzle.out","w",stdout);
 8     int n;
 9     cin>>n;
10     for(int i=1;i<=n;i++)
11     {
12         for(int j=1;j<=n;j++)
13         {
14             cin>>a[i][j];
15             if(a[i][j]=='#')
16                 s++;     
17         }
18     }
19     if(s%5!=0)
20     {
21         puts("NO");
22         return 0;
23     }
24     for(int i=1;i<=n;i++)
25     {
26         for(int j=1;j<=n;j++)
27         {
28             if(a[i][j]=='#')
29             {
30                 if(a[i+1][j]=='#' && a[i+1][j-1]=='#' && a[i+1][j+1]=='#' && a[i+2][j]=='#')
31                 {
32                     a[i+1][j]='.';
33                     a[i+1][j-1]='.';
34                     a[i+1][j+1]='.';
35                     a[i+2][j]='.';
36                 }
37                 else
38                 {
39                     puts("NO");
40                     return 0; 
41                 }
42             }
43         }
44     }
45     puts("YES");
46     return 0;
47 }

 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,a[5005],v[5005],ans,m;
 4 int main()
 5 {
 6     freopen("box.in","r",stdin);
 7     freopen("box.out","w",stdout);
 8     cin>>n;
 9     for(int i=1;i<=n;i++)
10         cin>>a[i];
11     sort(a+1,a+n+1);
12     for(int i=1;i<=n;i++)
13         if(!v[i])
14         {
15             ans++;
16             m=1;
17             for(int j=i+1;j<=n;j++)
18             if(!v[j]&&a[j]>=m)
19             {
20                 v[j]=1;
21                 m++;
22             }
23         }
24     cout<<ans<<endl;
25     return 0;
26 }

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 struct node{
 4     int x,y,z;
 5 }f[100005];
 6 int n,m,a[20005],vis[20005];
 7 bool cmp(node a,node vis)
 8 {
 9     return a.z>vis.z;
10 }
11 int find(int x)
12 {
13     if(a[x]==x)
14         return x;
15     a[x]=find(a[x]);
16     return a[x];
17 }
18 void add(int x,int y)
19 {
20     x=find(a[x]);
21     y=find(a[y]);
22     a[x]=y;
23 }
24 bool check(int x,int y)
25 {
26     x=find(x);
27     y=find(y);
28     if(x==y) return 1;
29     return 0;
30 }
31 int main()
32 {
33     freopen("love.in","r",stdin);
34     freopen("love.out","w",stdout);
35     cin>>n>>m;
36     for(int i=1;i<=n;i++)
37         a[i]=i;
38     for(int i=1;i<=m;i++)
39         cin>>f[i].x>>f[i].y>>f[i].z;
40     sort(f+1,f+m+1,cmp);
41     for(int i=1;i<=m+1;i++)
42     {
43         if(check(f[i].x,f[i].y))
44         {
45             cout<<f[i].z;
46             return 0;
47         }
48         else
49         {
50             if(!vis[f[i].x])
51                 vis[f[i].x]=f[i].y;
52             else
53                 add(vis[f[i].x],f[i].y);
54             if(!vis[f[i].y])
55                 vis[f[i].y]=f[i].x;
56             else
57                 add(vis[f[i].y],f[i].x);
58         }
59     }
60     return 0;
61 }

 

 1 #include <bits/stdc++.h>
 2 #define int long long
 3 using namespace std;
 4 const int mod = 998244353;
 5 vector < int > g[300005],v;
 6 int a[300005];
 7 bool vis[300005];
 8 int n,m,sum,ans=1;
 9 int qsm(int p,int q)
10 {
11     int re=1;
12     while(q!=0)
13     {
14         if(q&1)
15             re=re*p%mod;
16         p=p*p%mod;
17         q>>=1;
18     }
19     return re;
20 }
21 void dfs(int x,int dep)
22 {
23     vis[x]=1;
24     a[x]=dep;
25     for(int i=0;i<g[x].size();i++)
26     {
27         int t=g[x][i];
28         if(vis[t] && dep-a[t]>1)
29             v.push_back(dep+1-a[t]);
30         else if(!vis[t])
31             dfs(t,dep+1);
32     }
33     vis[x]=1;
34 }
35 signed main()
36 {
37     freopen("desert.in","r",stdin);
38     freopen("desert.out","w",stdout);
39     cin>>n>>m;
40     for(int i=1;i<=m;i++)
41     {
42         int x,y;
43         cin>>x>>y;
44         g[x].push_back(y);
45         g[y].push_back(x);
46     }
47     for(int i=1;i<=n;i++)
48         if(!vis[i])
49             dfs(i,1);
50     for(int i=0;i<v.size();i++)
51     {
52         ans=ans*(qsm(2,v[i])-1)%mod;
53         sum+=v[i];
54     }
55     ans=ans*qsm(2,m-sum)%mod;
56     cout<<ans;
57     return 0;
58 }

 

标签:std,8.5,记录,int,20,做题,freopen,using,return
From: https://www.cnblogs.com/wyh0721/p/17608238.html

相关文章

  • 7.31-8.5 每周总结
    这周大数据技术完成了zookeeper的学习,因为之前看的hbase看了一点之后,要安装hbase,就要先安装zookeeper,所以又去学习了zookeeper,算法与数据结构方面学习了链表,单链表,双链表,环形链表,学的不是很多,主要还是因为学习大数据遇到的问题很多,还有好多因为听不懂,又得返回去听,有些安装过程得一......
  • MySQL Server 5.5的安装及遇到问题记录
    一、安装安装没有什么说的,不会看图(版本,我选择自定义——Custom,供参考)                        --------------------------------------------------------------------------二、问题记录:安装后遇到的问题 1.安装mysql......
  • 8.5
    JavaArrayListArrayList类是一个可以动态修改的数组,与普通数组的区别就是它是没有固定大小的限制,我们可以添加或删除元素。ArrayList继承了AbstractList,并实现了List接口。ArrayList类位于java.util包中,使用前需要引入它,语法格式如下:importjava.util.ArrayList;//......
  • 8.4做题记录
    上午1#include<bits/stdc++.h>2usingnamespacestd;3intmain()4{5freopen("str.in","r",stdin);6freopen("str.out","w",stdout);7strings="a";8intn,k;9cin&......
  • 一文弄懂什么是DNS、A记录、CNAME以及使用方法
    域名解析DNS简介域名解析(DomainNameSystem,DNS)是互联网中用于将人类可读的域名(例如www.example.com)转换为计算机可理解的IP地址(例如192.168.1.1)的系统。它充当了互联网上的一个“电话簿”,帮助将用户提供的域名映射到实际的网络地址,使得计算机能够找到并连接到相应的网络服务器。白......
  • 2023.8.5
    学习java中的类面向对象与面向过程面向过程:强调的是功能行为,以函数为最小单位,考虑怎么做。面向对象:强调具备了功能的对象,以类/对象为最小单位类与对象的关系类:对一类事物的描述,是抽象的、概念上的定义对象:是实际存在的该类事物的每个个体,因而也称为实例(instance)面向对象......
  • jenkins 远程 ssh 部署问题记录
    脚本执行失败注意需要在sh脚本里面添加source/etc/profile脚本执行失败排查可以在jenkins的ssh命令添加日志,然后查看日志排错nohupsh/xx/xx.sh>/xx/xx.log2>&1&脚本编写注意事项在脚本开头添加cd到当前目录,确保脚本内部读取的路径正常......
  • GB28181智慧可视化指挥控制系统之执法记录仪设计探讨
    什么是智慧可视化指挥控制系统?智慧可视化指挥控制平台通过4G/5G网络、WIFI实时传输视音频数据至指挥中心,特别是在有突发情况时,可以指定一台执法仪为现场视频监控器,实时传输当前画面到指挥中心,指挥中心工作人员可通过麦克风向现场执法人员下达指令(语音广播或语音对讲)。本文主要介绍......
  • 电脑版微信聊天记录恢复导出工具(文字/语音/图片/视频/文件/表情包)
    PC版微信的聊天记录加密保存在电脑中,有时我们想将自己微信中的聊天记录导出来,但微信软件并不提供该功能。此软件可将自己电脑版微信中的聊天内容批量导出来。下载地址1:点击下载下载地址2:https://weijiesoft.lanzouw.com/i2oZq14gh19e可按照联系人名称创建文件夹自动分类,包括:文......
  • 实习随笔记录---写给自己看,不给任何人意见
    不要被贩卖焦虑......