Codeforces Gym 101608 - 2017 ACM Jordanian Collegiate Programming Contest

【竞赛】为啥用0x3f代表无穷大 以及memset用法简析 解释为啥用0x3f代表无穷大 以及memset用法简析 阅读详情

A. Chrome Tabs
time limit per test
2.0 s
memory limit per test
256 MB
input
tabs.in
output
standard output

Before participating in any online contest, you only keep the tab of the online contest open and close everything else.

You have n open tabs, numbered from 1 to n from left to right. Tab number k is the tab of the online contest and it is the current selected one. You have only two buttons:

  • Close all tabs to the left of the selected tab.
  • Close all tabs to the right of the selected tab.

What is the minimum number of clicks needed to close all tabs except tab number k?

Input

The first line of input contains a single integer T (1 ≤ T ≤ 5050), the number of test cases.

Each test case consists of a single line that contains two space-separated integers n and k(1 ≤ k ≤ n ≤ 100), the number of open tabs, and the tab of the online contest, respectively.

Output

For each test case, print the minimum number of clicks needed to close all tabs except the tab of the online contest.

Example
input
4
72 1
5 2
10 7
64 64
output
1
2
2
1


水题

#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#include <iomanip>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=100005,inf=0x3f3f3f3f;  
const ll llinf=0x3f3f3f3f3f3f3f3f;   
const ld pi=acos(-1.0L);

int main() {
	freopen("tabs.in","r",stdin);
	int cas;
	scanf("%d",&cas);
	while (cas--) {
		int n,k,pos,ans;
		scanf("%d%d",&n,&k);
		if (k==1||k==n) ans=1; else ans=2;
		if (k==1&&n==1) ans=0;
		printf("%d\n",ans);
	}
fclose(stdin);
	return 0;
}

B. OverCode
time limit per test
1.0 s
memory limit per test
256 MB
input
overcode.in
output
standard output

In a competitive coding contest called OverCode, matches are held between two teams. Each team must have exactly 6 coders. In order to form fair matches between coders, the absolute difference between the ratings of any two members of the same team shouldn't exceed 1000.

What is the maximum number of teams that can be formed out of n coders if you were given their ratings, such that each coder is a member of at most one team?

Input

The first line of input contains a single integer T (1 ≤ T ≤ 512), the number of test cases.

The first line of each test case contains a single integer n (1 ≤ n ≤ 500), the number of coders participating in OverCode.

The next line contains n space-separated integers r1, r2, ..., rn (1 ≤ ri ≤ 4000), ri is the rating of the ithcoder.

The total sum of n overall test cases doesn't exceed 1.5 × 105.

Output

For each test case, print the maximum number of teams that can be formed, on a single line.

Example
input
3
5
4 1 5 3 2
6
1 1001 2 4 3 5
13
7 9 7 2 1000 1001 2 3 9 4 5 2 5
output
0
1
2


排序之后贪心。

#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#include <iomanip>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=505,inf=0x3f3f3f3f;  
const ll llinf=0x3f3f3f3f3f3f3f3f;   
const ld pi=acos(-1.0L);
int a[maxn];

int main() {
	freopen("overcode.in","r",stdin);
	int cas;
	scanf("%d",&cas);
	while (cas--) {
		int n,i,j,ans=0;
		scanf("%d",&n);
		for (i=1;i<=n;i++) scanf("%d",&a[i]);
		sort(a+1,a+n+1);
		int cnt=1;j=1;
		for (i=2;i<=n;i++) {
			if (abs(a[i]-a[j])>1000) {
				ans+=cnt/6;
				while (abs(a[i]-a[j])>1000) j++;
				cnt=i-j+1;
			} else {
				cnt++;
				if (cnt==6) ans++,cnt=0,j=i+1; 
			}
		}
		printf("%d\n",ans);
	}
	fclose(stdin);
	return 0;
}
C. A message for you!
time limit per test
3.0 s
memory limit per test
256 MB
input
scoreboard.in
output
standard output

You’re participating in the ACM JCPC for the first time. Your team solved k out of the 13 problems. Since your last successful submission, you have been trying to solve new problems with no luck.

After all the frustration from the wrong answers, you decided to quit. You raised your head looking for a volunteer, then noticed a big white screen with some red and green dashes. You put your glasses on and, it is a scoreboard! You didn't know this contest has a scoreboard! Now that you do, you noticed that some problems have been solved by many teams! You decided to focus and try to solve the problem that has been solved by the maximum number of teams.

Input

The first line of input contains a single integer T (1 ≤ T ≤ 53235), the number of test cases.

The first line of each test case contains a single integer k (1 ≤ k < 13), the number of problems your team successfully solved.

The second line contains a string of k distinct uppercase English letters that represent the problems your team solved. The letters are given in the alphabetical order. Each problem from 1 to 13 has a corresponding letter from 'A' to 'M'.

The third line contains 13 integers t1, t2, ..., t13 (0 ≤ ti ≤ 92), ti is the number of teams that solved problem the ith problem.

It is guaranteed that the input is valid, and there's at least one problem not solved by your team and solved by other teams.

Output

For each test case, print an uppercase letter that represents the next problem to be solved, which is the one that has been completed by the maximum number of teams.

It is guaranteed that the answer is unique.

Example
input
3
2
CE
3 0 47 0 76 0 0 2 0 0 0 0 0
7
ADEFHLM
1 1 2 1 1 1 1 1 0 1 1 1 1
2
DG
35 14 40 13 11 18 1 7 41 29 8 19 43
output
A
C
M




水题,模拟。

#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#include <iomanip>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=55,inf=0x3f3f3f3f;  
const ll llinf=0x3f3f3f3f3f3f3f3f;   
const ld pi=acos(-1.0L);
int c[maxn];
char s[maxn];
bool a[maxn];

int main() {
	freopen("scoreboard.in","r",stdin);
	int cas;
	scanf("%d",&cas);
	while (cas--) {
		int n,i,ans;
		for (i=0;i<13;i++) a[i]=true;
		scanf("%d",&n);
		scanf("%s",s);
		for (i=0;i<n;i++) {
			a[s[i]-'A']=false;
		} 
		ans=-1;
		for (i=0;i<13;i++) {
			scanf("%d",&c[i]);
			if (a[i]) 
				if (ans==-1) ans=i; else 
					if (c[ans]<c[i]) ans=i;
		}
		printf("%c\n",(char)('A'+ans));
	}
	fclose(stdin);
	return 0;
}
D. Test Cases
time limit per test
2.0 s
memory limit per test
256 MB
input
cases.in
output
standard output

You want to prepare test cases for a problem with the following description:

"Given an array of n positive integers, and a number of queries. Each query will ask about a range [l, r](1 ≤ l ≤ r ≤ n), where each of the values between index l and index r (both inclusive) occurs an even number of times except one value. The answer to each query is the value that occurs an odd number of times in the given range."

You have generated an array of n positive integers, you need to know the number of valid queries you can ask on this array. A query is valid if it has an answer, and that answer is unique.

Input

The first line of input contains a single integer T (1 ≤ T ≤ 64), the number of test cases.

The first line of each test case contains a single integer n (1 ≤ n ≤ 5000), the size of the array.

The next line contains n space-separated integers, a1, a2, ..., an (1 ≤ ai ≤ 106), the values of the array.

The total sum of n overall test cases doesn't exceed 72000.

Output

For each test case, print a single line with the number of valid queries you can ask.

Example
input
1
7
9 1 1 2 1 9 9
output
12

暴力大法好,O(n^2)水过

#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#include <iomanip>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=5005,inf=0x3f3f3f3f;  
const ll llinf=0x3f3f3f3f3f3f3f3f;   
const ld pi=acos(-1.0L);
int a[maxn],cnt[1000005];

int main() {
	freopen("cases.in","r",stdin);
	int cas;
	scanf("%d",&cas);
	mem0(cnt);
	while (cas--) {
		int n,i,j,ans=0,o,e;
		scanf("%d",&n);
		for (i=1;i<=n;i++) {
			scanf("%d",&a[i]);
		}
		for (i=1;i<=n;i++) {
			o=e=0;
			for (j=i;j<=n;j++) {
				cnt[a[j]]++;
				if (cnt[a[j]]==1) e++; else 
					if (cnt[a[j]]%2) e++,o--; else e--,o++;
				if (e==1) ans++;
			}
			for (j=i;j<=n;j++) cnt[a[j]]=0;
		}
		printf("%d\n",ans);
	}
	fclose(stdin);
	return 0;
}
G. WiFi Password
time limit per test
2.0 s
memory limit per test
256 MB
input
wifi.in
output
standard output

Just days before the JCPC, your internet service went down. You decided to continue your training at the ACM club at your university. Sadly, you discovered that they have changed the WiFi password. On the router, the following question was mentioned, the answer is the WiFi password padded with zeros as needed.

A subarray [l, r] of an array A is defined as a sequence of consecutive elements Al, Al + 1, ..., Ar, the length of such subarray is r - l + 1. The bitwise OR of the subarray is defined as: Al OR Al + 1 OR ... OR Ar, where OR is the bitwise OR operation (check the notes for details).

Given an array A of n positive integers and an integer v, find the maximum length of a subarray such that the bitwise OR of its elements is less than or equal to v.

Input

The first line contains an integer T (1 ≤ T ≤ 128), where T is the number of test cases.

The first line of each test case contains two space-separated integers n and v (1 ≤ n ≤ 105)(1 ≤ v ≤ 3 × 105).

The second line contains n space-separated integers A1, A2, ..., An (1 ≤ Ai ≤ 2 × 105), the elements of the array.

The sum of n overall test cases does not exceed 106.

Output

For each test case, if no subarray meets the requirement, print 0. Otherwise, print the maximum length of a subarray that meets the requirement.

Example
input
3
5 8
1 4 5 3 1
5 10
8 2 6 1 10
4 2
9 4 5 8
output
5
3
0
Note

To get the value of x OR y, consider both numbers in binary (padded with zeros to make their lengths equal), apply the OR operation on the corresponding bits, and return the result into decimal form. For example, the result of 10 OR 17 = 01010 OR 10001 = 11011 = 27.



把每个数都拆成二进制记录每一位"1"的最晚出现时间,每次把合法区间的右界向右移一格,左界跟着一起移动(如果这时区间的或和超过所给上界),贪心的选择移动最少的方案。复杂度O(nlogn)。

贪心的依据是OR运算的单调不减性

#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#include <iomanip>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=100005,inf=0x3f3f3f3f;  
const ll llinf=0x3f3f3f3f3f3f3f3f;   
const ld pi=acos(-1.0L);
int a[maxn],last[25];

int main() {
	freopen("wifi.in","r",stdin);
	int cas;
	scanf("%d",&cas);
	while (cas--) {
		int n,i,k;
		scanf("%d%d",&n,&k);
		int u=k,p=0,div;
		while (u) {
			u/=2;
			p++;
		}
		div=p-1;
		for (i=0;i<=25;i++) last[i]=0;
		for (i=1;i<=n;i++) {
			scanf("%d",&a[i]);
		}
		int now=0,j=1,ans=0;
		for (i=1;i<=n;i++) {
			if (a[i]>k) {
				now=0;j=i+1;
				continue;
			}
			now=now|a[i];
			u=a[i],p=0;
			while (u) {
				if (u%2) last[p]=i;
				u/=2;
				p++;
			}
			if (now>k) 
		/*	if (last[div]!=i) {
				j=last[div]+1;
				now=0;
				for (int q=0;q<div;q++) {
					if (last[q]>=j) now=now|(1<<q);
				}
			} else */{
				int x=now,w=a[i],dig=inf;
				for (int q=0;q<=div;q++) {
					if (x%2==1&&w%2==0&&(now-(1<<q))<=k) {
						dig=min(dig,last[q]+1);
					}
					x/=2;w/=2;
				}
				if (dig==inf) dig=i;
				j=dig;
				now=0;
				for (int q=0;q<=div;q++) {
					if (last[q]>=j) now=now|(1<<q);
				}
			}
			ans=max(ans,i-j+1);
		}
		printf("%d\n",ans);
	}
	fclose(stdin);
	return 0;
}
M. Winning Cells
time limit per test
1.0 s
memory limit per test
256 MB
input
chess.in
output
standard output

You and your friend decided to play a new game using a squared chessboard of size n × n and one rook. Rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c.

The rules are simple, you and your friend will take turns, and you will start first. In each turn a player can move the rook at least 1 cell, and at most k cells in only one direction, either up or left, without going outside the chessboard. The player who moves the rook to the top-left cell (1, 1) wins.

You will choose the starting position for the rook. You are not allowed to choose the top-left cell. If you both will play optimally, how many cells can you choose as a starting position to win the game.

Input

The first line of input contains an single integer T (1 ≤ T ≤ 2 × 104), the number of test cases.

Each test case consists of a single line that contains two space-separated integers n and k(1 ≤ k < n ≤ 109), where n is the size of the chessboard, and k is the maximum allowed move.

Output

For each test case, print a single line that contains the number cells you can choose as a starting position to win the game.

Example
input
3
2 1
3 1
9 4
output
2
4
64



画图可以发现,对角线不行,对于n*n方阵相比(n-1)*(n-1)多出来的部分,横竖各每隔k个格子有一个不合法。由此可以推出公式。

#include <cstdio>
#include <iostream>
#include <string.h>
#include <string> 
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#include <iomanip>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int inf=0x3f3f3f3f;  
const ll llinf=0x3f3f3f3f3f3f3f3f;   
const ld pi=acos(-1.0L);

int main() {
	freopen("chess.in","r",stdin);
	int cas;
	scanf("%d",&cas);
	while (cas--) {
		ll n,k,ans;
		scanf("%I64d%I64d",&n,&k);
		if (n==k+1) ans=n*n-n; else {
			ll m=(n-1)/(k+1);
			ll a=m*2+1;
			ans=n*n-(k+1)-(k+1)*(3+a)*m/2;
			if (n%(k+1)!=0) 
				ans+=((k+1)-n%(k+1))*a;
		}
		printf("%I64d\n",ans);
	}
	fclose(stdin);
	return 0;
}
无穷大常量怎么选:0x3f3f3f3f、INT_MAX与溢出避坑 在C/C++算法实现中,程序没有数学意义的无穷大,常用一个足够大且不溢出的整型常量作为不可达或初始答案的哨兵值。核心原理在于int上限、松弛加法溢出与memset按字节填充:0x3f3f3f3f的两倍仍小于INT_MAX,且四个字节均为0x3f,可配合memset批量初始化;0x7fffffff虽语义明确却易在加法中溢出,0x3fffffff余量过小。选对无穷大常量能避免距离数组出现负数、DP状态污染和大数组初始化超时,在Dijkstra、Floyd、树形DP及多组数据场景中提升工程可靠性。关键是根据数值边 阅读详情

相关推荐

竞赛编程中0x3f3f3f3f的妙用:为什么它成了无穷大的代名词?

本文深入解析了竞赛编程中常用常数0x3f3f3f3f作为安全无穷大的原理与应用。它数值适中,能有效避免整数溢出,且与memset函数配合可实现高效数组初始化,广泛应用于图论最短路径、动态规划等算法场景,是提升竞赛代码性能与安全性的实用技巧。

weixin_29001423的博客 336

0x3f3f3f3f和0x3f3f3f3f3f3f3f3f分别代表

对于一些变量的初始化,我们希望它足够大,但是却又不希望它稍微变换一下就超出了数据范围,因此我们巧妙的用一个接近数据最大值的一个值INF。 若数据是int4位则定义#define INF 0x3f3f3f3f 大约是一个略大于1000000000的值。 若数据是long long16位则定义#define INF 0x3f3f3f3f3f3f3f3f大约是一个19位的值。 ...

mengxin_xiaobai的博客 5850

用RFSoC ZU47DR搭建软件无线电原型:从零配置Vivado到生成第一个射频信号

本文详细介绍了如何使用Xilinx RFSoC ZU47DR开发板搭建软件无线电原型系统,从Vivado环境配置到生成首个射频信号的全流程。通过整合ARM处理器、FPGA逻辑和高速ADC/DAC,该平台为通信算法验证提供了高效解决方案,特别适合SDR开发者和通信工程师快速实现原型设计。

weixin_26763955的博客 602

0x3f~0x3f3f3f3f的来龙去脉(详解)

0x3f~0x3f3f3f3f的来龙去脉

wenhaoyan的博客 1万+

【MCU开发规范】:车载MCU开发规范

车载MCU开发规范

1056

从零开始:手把手教你用VOACAP软件预测短波最佳工作频率(OWF)

本文详细介绍了如何使用VOACAP软件预测短波通信的最佳工作频率(OWF),涵盖软件安装、参数配置、电离层模型设置及结果解读。通过实战案例和优化技巧,帮助用户掌握短波传播特性,提升通信效率。特别适合业余无线电爱好者和专业通信人员参考。

weixin_30897079的博客 656

0x3f3f3f3f是什么意思

补充上课没好好听到的点

Selfishness_x的博客 2903

ADS1231驱动开发:24位高精度ADC嵌入式实现指南

24位Δ-Σ型ADC是高精度传感器信号采集的核心器件,其原理基于过采样与数字滤波实现远超奈奎斯特极限的分辨率。技术价值在于以低成本硬件达成微伏级信号分辨能力,显著提升称重、压力、力等桥式传感器系统的动态范围与温漂稳定性。典型应用场景涵盖电子秤、工业变送器及材料测试设备等对线性度、零点漂移和抗工频干扰(50/60Hz)有严苛要求的领域。本文围绕ADS1231这一面向惠斯通电桥优化的专用ADC,深入解析其串行同步时序驱动、PGA增益配置、参考电压匹配及FreeRTOS多任务安全集成等关键工程实践。

weixin_34268462的博客 629

0x3f3f3f3f(无穷大数)

一般定义无穷大数都是inf=99999999,或者0x7f ff ff ff,但是有的时候inf过大,虽然保证了没有数超过它,但是在需要加上一个数的时候,inf+a可能会导致溢出,最终变成一个负数。 而0x3f3f3f3f的数量级也1e9的,(一般题不会给超过1e9的数),在把它当成无穷大的时候,两个0x3f3f3f3f相加的结果也不会爆int。所以这个数比较合适了。 并且如果开一个数组,让数组中...

H4ppyD0g的博客 1322

攻克低照度检测难题:YOLOv11主干网络增强新方案PE-YOLO详解

编码器部分# 解码器部分self.dec_conv2 = nn.Conv2d(512, 128, 3, padding=1) # 跳跃连接self.dec_conv3 = nn.Conv2d(256, 64, 3, padding=1) # 跳跃连接self.dec_conv4 = nn.Conv2d(128, 32, 3, padding=1) # 跳跃连接# 编码路径# 解码路径(带跳跃连接)

FJN110的博客 119

vue - 网站接入微信扫码登录功能详细教程,完整详细流程及完整功能示例源代码(附常见问题的解决方案与二维码样式修改方案)

vue.js项目植入微信登录,vue网页项目怎么做微信扫码登录,VUE项目中的微信扫码登录,VUE中最简单的js调用微信扫一扫功能,vue:如何设计网页的微信扫码登录功能,微信扫码功能官方文档,通过vue方式实现二维码扫码功能,vue调用微信扫码,vue H5 调用微信扫描二维码,Vue前端实现微信扫码登录,vue-wxlogin 微信授权登录组件,网站引入的微信登录框如何修改宽高或其他样式,wxlogin 组件插件怎么改变宽高,vue-wxlogin组件怎么自定义样式,微信网页授权,vue调用微信JSDK

✅ 精选推荐文章 6372

2017 ACM Jordanian Collegiate Programming Contest (1/13)

G. WiFi Password 题意 给一个n个数的数组,询问小于等于v的或(or)最大区间,or区间(l<=x<=r)的定义:a【l】|a【l+1】|......|a【r】 (一共有128次输入,n <= 1e5,v<=3e5,a【i】 <= 2e5) 分析 对每一个数二进制位进行考虑,然后双指针的扫一下,双指针扫的时候注意指针的位置...

auiayo82822的博客 220

人形机器人硬件电路设计入门

人形机器人属于。

blotemj.blog.csdn.net 240

笔记29:关于设置无穷大为【#define INF 0x3f3f3f3f】的原因

INF=0x3f3f3f3f是 什么意思?_AEP_WYK的博客-CSDN博客总结一下:一共4个原因1.因为 0x3f3f3f3f 他的十进制数字和 0x7fffffff 一样,数量级都是10的9次方级,都足够大可以当作无穷大使用。

weixin_44063383的博客 686

使用 Python 调用 GitHub REST API 爬取 GitHub 仓库信息(完整指南)

GitHub 提供了功能强大的 REST API,允许开发者通过编程方式访问 GitHub 上的仓库、用户、提交记录、PR(Pull Request)等信息。GitHub REST API 是 GitHub 官方提供的 API 接口,支持通过 HTTP 请求来操作 GitHub 上的资源。在本文中,我们将使用 Python 编写一个完整的爬虫程序,调用 GitHub 的 REST API 来爬取 GitHub 仓库的信息。目前 GitHub 使用的主要是 v3 版本的 REST API。

2201_76125261的博客 1116

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

2017 ACM Jordanian Collegiate Programming Contest

hh 转载于:https://www.cnblogs.com/Deadline/p/9033294.html

amwm52937的博客 122

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

LLONG_MAX和0x3f3f3f3f的区别及后续知识补充

区别

2301_81977319的博客 904

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

0x3f3f3f3f 和0x3f3f3f3f3f3f3f3f

对于一些变量的初始化,我们希望它足够大,但是却又不希望它稍微变换一下就超出了数据范围,因此我们巧妙的用一个接近数据最大值的一个值INF。若数据是long long16位则定义#define INF 0x3f3f3f3f3f3f3f3f大约是一个19位的值。若数据是int4位则定义#define INF 0x3f3f3f3f 大约是一个略大于1000000000的值。

z_zssss的博客 342

0x3f3f3f3f知多少

0x3f3f3f3f的十进制是1061109567,也就是10^9级别的(和0x7fffffff一个数量级),而一般场合下的数据都是小于10^9的,所以它可以作为无穷大使用而不致出现数据大于无穷大的情形。另一方面,由于一般的数据都不会大于10^9,所以当我们把无穷大加上一个数据时,它并不会溢出(这就满足了“无穷大加一个有穷的数依然是无穷大”),事实上0x3f3f3f3f+0x3f3f3f3f=21

菜鸟 6647

0x3f3f3f3f是什么意思???

ACM中常用的无穷大常量——0x3f3f3f3f 最近做题看题解的时候发现在大佬的题解报告中常会出现这么一行:↓↓↓ const int inf = 0x3f3f3f3f; 然后我就去探索了一下,0x3f3f3f3f的十进制是1061109567,是10^9级别的,而一般场合下的数据都是小于10^9的,所以它可以作为无穷大使用而不致出现数据大于无穷大的情形。 一般dfs或者dp求最小值......

qq_31267769的博客 4万+

0x3F3F3F3F——算法比赛中的无穷大常量

在算法竞赛中,我们常常需要用到设置一个常量用来代表“无穷大”。 比如对于int类型的数,有的人会采用INT_MAX,即0x7fffffff作为无穷大。但是以INT_MAX为无穷大常常面临一个问题,即加一个其他的数会溢出。 而这种情况在动态规划,或者其他一些递推的算法中常常出现,很有可能导致算法出问题。 所以在算法竞赛中,我们常采用0x3f3f3f3f来作为无穷大。0x3f3f3f3f主要有如下好处: 0x3f3f3f3f的十进制为1061109567,和INT_MAX一个数量级,即10^9数量级,而一般场合

Yannie's Blog 1777

2017 ACM Amman Collegiate Programming Contest

A - Watching TV /* 题意:求出出现次数最多的数字 */ #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int T,n,a[100010]; char s[110]; int main(){ s...

weixin_30793643的博客 257

2017 ACM Amman Collegiate Programming Contest L. The Shortest Path(超级源点+判负环)

思路:建立超级源点,设置为0,将它到任何点的距离都设置为0,则可以发现,若无负环并且最小边<=0时,可以求出最小距离,但若最小边大于0时,提前输出最小边, 看这组数据:3 3 1 2 3 2 3 2 1 3 1 若按照刚刚的判,输出是0,程序默认把最小距离当成设置的超级源点到任何一个点的距离了,至于如何判负环,定义lop数组来存深度,若深度大于n,则有边被访问两次,有负环。 ...

Endeavor_G的博客 297

Gym - 101608D(区间问题)

You want to prepare test cases for a problem with the following description: "Given an array of n positive integers, and a number of queries. Each query will ask about a range [l, r] (1 ≤ l ≤ r ≤ n),...

Fusheng_Yizhao的博客 737

2017 ACM Jordanian Collegiate Programming Contest I(Counting Votes-特征值)

在一个n*m的白板上有若干8联通联通块,每块必须是字母(H,M,Y) 中的一个,统计白板上各字母出现次数。注意各字母字体相同. 记录特征值。#include<bits/stdc++.h> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #def

nike0good |Oier&ACMer | 熟能生巧 732
上一篇: BZOJ 3238 [Ahoi2013]差异 后缀数组+单调栈
下一篇: AtCoder Regular Contest 076 F - Exhausted? 贪心
VampireWeekend
博客等级 码龄10年 47粉丝 289原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值