Tag: 算法

我在哪里可以找到++运算符的实现?

在哪里可以找到数字和指针的++运算符的C / C ++实现? 我环顾网络,但没有找到太多……

使用getchar()获取多个值。

我可以以某种方式使用getchar()来运行命令行,直到我点击’\ n’。 假设我想要扫描我输入的所有值,例如。 21 23 1 78 54’\ n’。 我想将所有五个值扫描到一个数组中。 我无法扫描它们。是不是因为每个值之间的间距? 或者是否有我们可以使用的function? 提前致谢

路线位于像二维arrays的盒子里

我的代码: #include #include int ch,a[100]; static int i=0,j; int checkIfValidCoordinates(int x, int y, int n, char arr[]){ if(x==a[i]&& y==a[i+1]) { i+=2; return 0; } // arr for this location is invalid // then return 0; return 1; } void path(int u,int v,int n,char arr[],size_t s,size_t p) { ch=1; int x; j=checkIfValidCoordinates(u,v,n,arr); if(j == 0) return; […]

如何计算一系列数字中的谷数?

给定一系列数字,谷被定义为序列中由较高值围绕(向左和向右)的区域。 任务是找到序列中的谷数。 例如, {9,8,7,7,8,9} has one valley at {7,7} {9,8,7,7,8,6,9} has two valleys at {7,7} and {6} {7,8,9,8,7} has no valleys 我必须计算山谷数量的代码如下: #include #define SIZE 40 int main() { int input; int store[SIZE]; int i = 0; int j; int valley = 0; int count = 0; printf(“Enter sequence: “); scanf(“%d”, &input); while(input != -1) […]

C中数字的排列

我正在尝试编写一个C函数来列出一组数字的所有排列,以五个为一组,包括重复数字: 15-11-49-43-5 2-30-34-6-11 所以编写一个函数来获取一个数字集的所有排列并将它们抛出是很容易的,但是映射到某个组大小,我有点卡住..

插入已排序的数组

我想在正确的位置插入一个元素,该顺序在排序列表中维护。 我为arrays分配了2 * n的大小,并用999填充其余的,因为它们目前没有使用。 ordered_insert(int number,int array[],int size){ int i=0; int temp1,temp2,index; while(eleman>array[i]){ i++;} //push the rest to right by one index=i; if(i<size){ temp1=array[i]; temp2= array[i+1]; array[i+1]=temp1; array[i+2]=temp2; i++; } array[index]=number; } 我无法弄清楚如何覆盖999s或者有更好的方法吗?

C中arcsin的逼近

我有一个程序可以根据Taylor的序列计算arcsin值的近似值。 我的朋友和我已经提出了一个能够返回几乎“正确”值的算法,但我认为我们并没有非常清晰地完成它。 看一看: double my_asin(double x) { double a = 0; int i = 0; double sum = 0; a = x; for(i = 1; i < 23500; i++) { sum += a; a = next(a, x, i); } } double next(double a, double x, int i) { return a*((my_pow(2*i-1, 2)) / ((2*i)*(2*i+1)*my_pow(x, 2))); } […]

如何逆转文件中的行顺序

我们怎样才能尊重文件中的行顺序而不是行本身。 文件可以变得很大。 不应该假设线的长度。 输入: this is line1 this is line2 this is line3 示例输出: this is line3 this is line2 this is line1 我虽然使用另一个文件作为缓冲区,就像堆栈数据结构一样,但实际上并没有随处可见。 有什么想法吗?

2个旋转立方体之间的碰撞检测

可能重复: 两个一般六面体之间的碰撞检测 现在我通过找到最小值和最大值并进行边界框检查来进行碰撞检测。 不幸的是,我的播放器立方体与相机一起旋转,当玩家处于45度角时,这会产生一些烦人的结果。 限制是每个立方体都是轴对齐并且有8个顶点,但是玩家可能会旋转(基本上我对每个顶点都是sin,cos并围绕立方体的中心旋转。鉴于此,我怎样才能进行准确的碰撞检测我的播放器是旋转的? 谢谢

如何正确测量CUDA时间?

我试图正确测量并行和顺序执行的时间,但我怀疑是因为: 假设我们有以下代码: //get the time clock_t start,finish; double totaltime; start = clock(); double *d_A, *d_B, *d_X; cudaMalloc((void**)&d_A, sizeof(double) * Width * Width); cudaMalloc((void**)&d_B, sizeof(double) * Width); cudaMalloc((void**)&d_X, sizeof(double) * Width); cudaMemcpy(d_A, A, sizeof(double) * Width * Width, cudaMemcpyHostToDevice); cudaMemcpy(d_B, B, sizeof(double) * Width, cudaMemcpyHostToDevice); do_parallel_matmul<<>>(d_A, d_B, d_X, Width); cudaMemcpy(X, d_X, sizeof(double) * Width, cudaMemcpyDeviceToHost); finish […]