C语言
志存高远CS
这个作者很懒,什么都没留下…
展开
-
c与c++直接排序算法
头文件:include using namespace std;1.默认的sort函数是按升序排。对应于1) sort(a,a+n); //两个参数分别为待排序数组的首地址和尾地址 2.可以自己写一个cmp函数,按特定意图进行排序。对应于2) 例如: int cmp( const int &a, const int &b ){ if( a > b ) return 1; else r原创 2017-02-14 09:36:20 · 197 阅读 · 0 评论 -
getline应用
The objective of the program you are going to produce is to evaluate boolean expressions as the one shown next: Expression: ( V | V ) & F & ( F | V ) where V is for True, and F is for False. The expr原创 2017-02-19 20:15:18 · 244 阅读 · 0 评论 -
实现数字逆序的方法
很多时候需要实现数字逆序,比如456逆序之后为654,依此类推。首先考虑十进制的情况,想到读入一个数时,对10取余数,然后除10,逐渐输出,需要考虑的是负数时需要通过一个负号变为正数,即#includevoid main(){ int n; scanf("%d",&n);if(n<0){n=-n;}while(n>0){ printf("%d",n%10);原创 2017-08-08 17:33:34 · 4460 阅读 · 0 评论 -
红色警戒思考
天梯赛题目红色警戒,是一个图的连通性问题,大概可以考虑dfs邻接矩阵,dfs邻接表vector,并查集三种思路#include <bits/stdc++.h>using namespace std;int a[1000][1000],n,sum=0,m;int vis[55000];/* run this program using the console pauser or ...原创 2018-03-26 14:26:47 · 400 阅读 · 1 评论 -
列车调度思考
原始的贪心模拟列车调度算法如下#include<bits/stdc++.h>using namespace std;int main(){ int n,i,j=0,flag,cnt=0,t,a[100010],b[100010]; cin>>n; memset(b,0,sizeof(b)); cin>>a[0]; b[0]=a[0]; for(i...原创 2018-03-26 16:05:32 · 364 阅读 · 0 评论 -
愿天下有情人都是失散多年的兄妹思考
这个题可以用dfs,bfs等等方法去看五代的情况,用dfs挺复杂的#include<bits/stdc++.h>using namespace std;int cnt=0;set<int> c;int vis[100100],exist[100100],yvis[100100];struct people{ int sex; int id; int f...原创 2018-03-26 19:14:18 · 410 阅读 · 0 评论