首页 > 其他分享 >2022.11.18

2022.11.18

时间:2022-11-19 09:45:49浏览次数:34  
标签:ch ++ 18 long int while && 2022.11

T1

很明显的暴力,首先可以看到就是一个二进制加法,在二进制下的某一位上 加一,直接模拟即可
期望得分 \(100\)

代码如下

/*

     />    フ
     |  _  _|
     /`ミ _x 彡
     /      |
    /   ヽ   ?
 / ̄|   | | |
 | ( ̄ヽ__ヽ_)_)
 \二つ

*/
#include<bits/stdc++.h>
using namespace std;

long long read()
{
    long long x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}

char s[1000100];

int a[1000100], ans, n, m;

int main()
{
	n = read();
	scanf("%s", s);
	for(int i = 0; i < n; i++)
	{
		if(s[n - i - 1] == '0') a[i] = 0;
		else a[i] = 1; 
	}
	n += 30;
	m = read();
	while(m--)
	{
		int x = read();
		ans = 0;
		++a[x];
		ans++;
		while(a[x] >= 2) ++a[x + 1], a[x] -= 2, ++x, ++ans; 
		cout << ans << '\n';
	}
	for(int i = n - 1; i >= 0; i--)
	{
		if(a[i] != 0)
		{
			for(int j = i; j >= 0; j--)
			{
				cout << a[j];
			}
			break;
		}
	}
    return 0;
}

T2

一道找规律题,玩玩小样例看不出来,但是大样例的规律挺明显的,如果有负数,那就取连续的负数中最小的一个(其实取哪一个都一样,但是std是这么构造的),对于正数,直接取,不需要删去.

期望分数100

/*

     />    フ
     |  _  _|
     /`ミ _x 彡
     /      |
    /   ヽ   ?
 / ̄|   | | |
 | ( ̄ヽ__ヽ_)_)
 \二つ

*/
#include<bits/stdc++.h>
using namespace std;

long long read()
{
    long long x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}

int n;

int a[2000010];

int cnt, maxn = -0x3f3f3f3f;

int b[2000010];

long long ans;

int main()
{
	n = read();
	a[0] = 0;
	for(int i = 1; i <= n; i++) a[i] = read();
	for(int i = 1; i <= n; i++)
	{
		if(a[i] >= 0 && a[i - 1] < 0)
		{
			b[++cnt] = maxn;
			maxn = -0x3f3f3f3f;
			b[++cnt] = a[i];
		}
		if(a[i] < 0)
		{
			maxn = max(maxn, a[i]);
		}
		if(a[i] >= 0 && a[i - 1] >= 0) b[++cnt] = a[i];
	}
	if(maxn != -0x3f3f3f3f && b[cnt] >= 0) b[++cnt] = maxn;
	for(int i = 2; i <= cnt; i++)
	{
		ans += max(b[i], b[i - 1]);
	}
	cout << ans << "\n";
	cout << cnt << "\n";
	for(int i = 1; i <= cnt; i++)
	{
		cout << b[i] << " ";
	}
    return 0;
}

T3

35分写法:
直接 \(n^2\) 暴力建图,邻接矩阵判重 + 链式前向星存图

建完图直接跑最短路就行

如果 \(n\) > \(10^4\) 直接输出 \(-1\)

考场上数组开小挂掉 \(10\) 分

原因: 因为最大可能有 \(n^2\) 条边,而数组只开到了 \(m\)

代码如下:

/*

     />    フ
     |  _  _|
     /`ミ _x 彡
     /      |
    /   ヽ   ?
 / ̄|   | | |
 | ( ̄ヽ__ヽ_)_)
 \二つ

*/
#include<bits/stdc++.h>
using namespace std;

long long read()
{
    long long x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}

int n, m, tot; 

int head[100010], ver[100010], nex[100010], edge[100010];

int a[100010], b[100010], c[100010];

int e[1010][1010], d[1010];

bool v[1010];

void add(int x, int y, int z)
{
	ver[++tot] = y;
	nex[tot] = head[x];
	head[x] = tot;
	edge[tot] = z;
}

void dijkstra()
{
	memset(d, 0x3f, sizeof(d));
	priority_queue<pair<int,int> > q;
	d[1] = 0;
	q.push({0, 1});
	while(!q.empty())
	{
		int x = q.top().second;
		q.pop();
		if(v[x]) continue;
		v[x] = 1;
		for(int i = head[x]; i; i = nex[i])
		{
			int y = ver[i];
			if(d[y] > d[x] + edge[i])
			{
				d[y] = d[x] + edge[i];
				q.push({-d[y], y});
			}
		}
	}
}

int main()
{
	memset(e, 0x3f, sizeof(e));
	n = read(), m = read();
	if(n > 1e4)
	{
		cout << -1;
		return 0; 
	}
	for(int i = 1; i <= n; i++)
	{
		a[i] = read();
		b[i] = read();
		c[i] = read();
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1;  j <= n; j++)
		{
			if(i == j) continue;
			if((a[i] ^ a[j]) >= b[i])
			{
				e[i][j] = min(e[i][j], c[i] +c[j]);
			}
		}
	}
	for(int i = 1; i <= m; i++)
	{
		int x = read(), y = read(), z = read();
		e[x][y] = min(e[x][y], z);
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			if(i == j) continue;
			if(e[i][j] != 0x3f3f3f3f)
			{
				add(i, j, e[i][j]);
			}
		}
	}
	dijkstra();
	if(d[n] == 0x3f3f3f3f) cout << -1;
	else cout << d[n]; 
    return 0;
}

T4

标签:ch,++,18,long,int,while,&&,2022.11
From: https://www.cnblogs.com/Han-han-/p/16905472.html

相关文章

  • 11.18日学习记录
    2022-11-1813:41:421.TOMCAT的配置tomcat的配置搞了一个上午,还让别人帮了忙,主要是因为tomcat位置放的不好。貌似放在桌面不行,改放在了D盘下,终于解决了之前tomcat启动成......
  • 解决centos7.6找不到GLIBC_2.18
    问题原因:启动node服务,报错GLIBC_2.18nofound,同时也报错 /lib64/libstdc++.so.6versionCXXABI_1.3.9nofound查看系统GLIBC版本:[root@VM_0_7_centoslib64]#stri......
  • day18-web工程路径
    web工程路径配置tomcat运行快捷键tomcat启动的默认快捷键时shift+f10,可以自定义配置:file-setting-keymap-搜索run,找到右边写有shift+f10的选项,右击选择addkeyboardsh......
  • 17-18.导入csv
    *导入CSV文件.pd.read_csv(filepath_or_buffer,sep=',header,encoding=None)常用参数说明.# filepath_or_buffer:字符串、文件路径,也可以是URL链接# sep:字符串......
  • 2022-11-18 Acwing每日一题
    本系列所有题目均为Acwing课的内容,发表博客既是为了学习总结,加深自己的印象,同时也是为了以后回过头来看时,不会感叹虚度光阴罢了,因此如果出现错误,欢迎大家能够指出错误,我......
  • 18.正则表达式
    正则表达式认识正则正则表达式,又称规则表达式,(RegularExpression,在代码中常简写为regex、regexp或RE),是一种文本模式,包括普通字符(例如,a到z之间的字母)和特殊字符(称为"......
  • 11.18 解题报告
    A考场用时:\(1\)h期望得分:\(100\)pts实际得分:\(100\)pts不难推出:总代价即为所有逆序对的差的绝对值之和,这个直接树状数组维护就行了。#include<bits/stdc++.h>#def......
  • 11.18 解题报告
    总的来说没挂分,因为没啥分可以挂了。预计得分:60+0+20+20实际得分:60+0+15+20A预计得分:60实际得分:60写了n^2的暴力+特殊性质特殊性质用暴力来......
  • 2022-11-18学习内容
    1.案例-购物车-清空购物车1.1ShoppingCartActivity.javapackagecom.example.chapter06;importandroidx.appcompat.app.AppCompatActivity;importandroid.app.Ale......
  • 【题解】做题记录(2022.11)
    11.1CF449DJzzhuandNumbers题目分析:考虑直接算的话就相当于限制每一位必须有一个\(0\),显然不如反着来,也就是某一位必须全为\(1\),也就是我们计算与之后不为\(0\)......