Summer training

2024-03-02 08:08
文章标签 training summer

本文主要是介绍Summer training,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

补题内容:

1,当时没做出来的,必补

2,当时做出来但是感觉写的很挫,或者觉得出的很好的题

题意都不说,这篇博客的意义是让我踏实把这些题都弄透

Day1:

不容易系列之(4)——考新郎

这个另外一个博客中已经写了https://blog.csdn.net/swunHJ/article/details/81123246

记住并理解错排递推式f[n] = (n - 1) * (f[n-1] + f[n-2]);

Day2:

dfs, 没啥觉得很好的题

Day3:

bfs,A计划,这个还挺有意思的,补过,为了锻炼码力,再敲一遍试试。

解题思路:很明显的bfs,难点在于如何在两层之间变换,解决方案是开一个三维数组来保存这两层,然后注意一下层之间的切换和check的内容即可,噢,难点还在于不好写。

写代码的思路:还是按部就班地bfs,遇到了传送门就处理一下,再加上特判。

考虑如何处理传送:三维数组嘛,我们用0和1来表示两层,bfs的时候就分情况,是‘#’就采取floor = 1 - floor,就转换到处理另一层

考虑需要check的内容:

1,传送是否会撞墙,是否会死循环(两层的对应位置都是传送门)

2,基本的是否越界、是否可走、是否访问过

AC Code:

#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define FAST ios::sync_with_stdio(false)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)2e5 + 5;
using namespace std;struct Point{int x, y, f, step;Point(int tx = 0, int ty = 0, int tf = 0, int tstep = 0){x = tx, y = ty, f = tf, step = tstep;}
};char G[2][15][15];
bool vis[2][15][15];
int dir[4][2] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
int n, m, max_t;
queue<Point> q;
bool flag;bool check(Point P){if(P.x < 0 || P.x >= n || P.y < 0 || P.y >= m) return false;if(vis[P.f][P.x][P.y] || G[P.f][P.x][P.y] == '*') return false;return true;
}int bfs(){Point start;start.f = 0, start.x = 0, start.y = 0, start.step = 0;q.push(start);vis[0][0][0] = 1;while(!q.empty()){Point now = q.front(); q.pop();if(G[now.f][now.x][now.y] == 'P'){flag = true;if(now.step <= max_t) return 0 * puts("YES");else return 0 * puts("NO");}Point next;if(G[now.f][now.x][now.y] == '#'){next.f = 1 - now.f, next.x = now.x, next.y = now.y;if(check(next) && G[next.f][next.x][next.y] != '#'){next.step = now.step;q.push(next);vis[next.f][next.x][next.y] = 1;}}else {for(int i = 0; i < 4; i++){next.f = now.f, next.x = now.x + dir[i][0], next.y = now.y + dir[i][1];if(check(next)){next.step = now.step + 1;q.push(next);vis[next.f][next.x][next.y] = 1;}}}}
}int main()
{int t; scanf("%d", &t);while(t--){while(!q.empty()) q.pop();memset(vis, false, sizeof(vis));scanf("%d %d %d", &n, &m, &max_t);for(int i = 0; i < 2; i++){for(int j = 0; j < n; j++){scanf(" %s", G[i][j]);}}flag = false;bfs();if(!flag) puts("NO");}return 0;
}

哈密顿绕行世界问题

一个体现dfs序的优越性的题目,控制优先级:编号从小到大,进行dfs即可

需要注意的就是输入的时候要排个序,不过这题数据很友好,排好了

考虑一下dfs思路:走完了一圈就输出

没走完继续找,注意标记,回溯完了得重新vis标为0,基本操作了,不多讲

AC Code:

#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define FAST ios::sync_with_stdio(false)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)2e5 + 5;
using namespace std;int a[25][5], step[25];
bool vis[25];
int m, cnt;void dfs(int cur, int len){if(cur == m && len == 21){printf("%d: ", cnt);cnt++;for(int i = 1; i <= 21; i++){printf(" %d", step[i]);}puts("");return ;}for(int i = 1; i <= 3; i++){int t = a[cur][i];if(!vis[t]){vis[t] = 1;step[len+1] = t;dfs(t, len + 1);vis[t] = 0;}}
}int main()
{for(int i = 1; i <= 20; i++){for(int j = 1; j <= 3; j++){scanf("%d", &a[i][j]);}}while(~scanf("%d", &m) && m){cnt = 1;memset(vis, false, sizeof(vis));step[1] = m;dfs(m, 1);}return 0;
}

 

Day4:二分,快速幂,gcd一些杂东西

C. Success Rate

你现在提交了y份答案,x份是对的,你想把正确率变成p/q,问最少还要提交多少题

如下考虑:又提交了dy份,其中dx份是对的,那么(x + dx) / (y + dy) == p / q

考虑一个倍数k,那么x + dx = k * p, y + dy = k * q

这时候我们只需要二分枚举倍数k,即可获得正确答案ans = dy = k * q - y

再考虑二分的细节。首先,二分起点,题目中给的数据范围是1e9,那么init l = 0, r = 1e9

要求尽可能小的提交次数,那么k肯定越小越好,所以在右端点处更新ans

考虑check的内容,其实很简单,枚举了一个k,那么只需要满足dy >= dx >= 0即可

还有就是注意开ll,会爆int

Ac Code:

#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define FAST ios::sync_with_stdio(false)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)2e5 + 5;
using namespace std;ll x, y, p, q;bool check(ll k){ll dx = k * p - x, dy = k * q - y;if(dy >= dx && dx >= 0) return true;return false;
}int main()
{int t; scanf("%d", &t);while(t--){scanf("%I64d %I64d %I64d %I64d", &x, &y, &p, &q);ll ans = -1;ll l = 0, r = 1e9;while(l <= r){ll mid = (l + r) >> 1;if(check(mid)){r = mid - 1;ans = mid;}else l = mid + 1;}if(ans == -1) puts("-1");else printf("%I64d\n", ans * q - y);}return 0;
}

其他没啥好说的

先到这,待我把昨天没打的cf给补了。。。

Day5:

这个G我是真的不想补。。。

 

 

 

 

 

 

这篇关于Summer training的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/765456

相关文章

2014 Multi-University Training Contest 8小记

1002 计算几何 最大的速度才可能拥有无限的面积。 最大的速度的点 求凸包, 凸包上的点( 注意不是端点 ) 才拥有无限的面积 注意 :  凸包上如果有重点则不满足。 另外最大的速度为0也不行的。 int cmp(double x){if(fabs(x) < 1e-8) return 0 ;if(x > 0) return 1 ;return -1 ;}struct poin

2014 Multi-University Training Contest 7小记

1003   数学 , 先暴力再解方程。 在b进制下是个2 , 3 位数的 大概是10000进制以上 。这部分解方程 2-10000 直接暴力 typedef long long LL ;LL n ;int ok(int b){LL m = n ;int c ;while(m){c = m % b ;if(c == 3 || c == 4 || c == 5 ||

2014 Multi-University Training Contest 6小记

1003  贪心 对于111...10....000 这样的序列,  a 为1的个数,b为0的个数,易得当 x= a / (a + b) 时 f最小。 讲串分成若干段  1..10..0   ,  1..10..0 ,  要满足x非递减 。  对于 xi > xi+1  这样的合并 即可。 const int maxn = 100008 ;struct Node{int

Post-Training有多重要?一文带你了解全部细节

1. 简介 随着LLM学界和工业界日新月异的发展,不仅预训练所用的算力和数据正在疯狂内卷,后训练(post-training)的对齐和微调方法也在不断更新。InstructGPT、WebGPT等较早发布的模型使用标准RLHF方法,其中的数据管理风格和规模似乎已经过时。近来,Meta、谷歌和英伟达等AI巨头纷纷发布开源模型,附带发布详尽的论文或报告,包括Llama 3.1、Nemotron 340

2015 Multi-University Training Contest 5 1009 MZL#39;s Border

MZL's Border  Problem's Link:  http://acm.hdu.edu.cn/showproblem.php?pid=5351   Mean:  给出一个类似斐波那契数列的字符串序列,要你求给出的f[n]字符串中截取前m位的字符串s中s[1...i] = s[s.size()-i+1....s.size()]的最大长度。 analyse:   过计算

[论文解读]Genre Separation Network with Adversarial Training for Cross-genre Relation Extraction

论文地址:https://www.aclweb.org/anthology/D18-1125.pdf发表会议:EMNLP2019 本论文的主要任务是跨领域的关系抽取,具体来说,利用某个领域的数据训练好的关系抽取模型,很难去直接抽取另一个领域中的关系,比如我们拿某个领域训练好的模型,把另一个领域的数据直接输入整个模型,很难抽取出来正确的实体关系。这主要是因为源领域和目标领域特征表达的不同,在源

2014 Multi-University Training Contest 1/HDU4861_Couple doubi(数论/规律)

解题报告 两人轮流取球,大的人赢,,, 贴官方题解,,,反正我看不懂,,,先留着理解 关于费马小定理 关于原根 找规律找到的,,,sad,,, 很容易找到循环节为p-1,每一个循环节中有一个非零的球,所以只要判断有多少完整循环节,在判断奇偶,,, #include <iostream>#include <cstdio>#include <cstring>

HDU1827 Summer Holiday(强连通+缩点+最小传递费用)

题意:给出人物关系图,要把一个通知告诉所有人,告诉每一个人有一个费用,现在想知道最小通知的人与费用。 思路:利用Tarjan算法,对原图进行缩点,然后找出入度为0 的点,那么这个人是必须要通知的,由于经过缩点,所以,如果这个点是缩点来的,那就枚举下这个点里的任一个点,找到最小的费用点。 #include<cstdio>#include<iostream>#include<algorith

一文彻底搞懂Fine-tuning - 预训练和微调(Pre-training vs Fine-tuning)

Pre-training vs Fine-tuning 预训练(Pre-training)是预先在大量数据上训练模型以学习通用特征,而微调(Fine-tuning)是在特定任务的小数据集上微调预训练模型以优化性能。 Pre-training vs Fine-tuning 为什么需要预训练? 预训练是为了让模型在见到特定任务数据之前,先通过学习大量通用数据来捕获广泛有用的特征,从而

poj 3735 Training little cats(构造矩阵)

http://poj.org/problem?id=3735 大致题意: 有n只猫,开始时每只猫有花生0颗,现有一组操作,由下面三个中的k个操作组成: 1. g i 给i只猫一颗花生米 2. e i 让第i只猫吃掉它拥有的所有花生米 3. s i j 将猫i与猫j的拥有的花生米交换 现将上述一组操作循环m次后,问每只猫有多少颗花生? 很明显,要先构造矩阵,构造一个(n+1)