随笔分类 - SDUT
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2321题意:第一次用java写代码。。纪念一下。。虽然写的有点挫。。 1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 5 public class Main { 6 7 public static void main(String[] args) { 8 9 Scanner cin = new Scanner(Syste...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2833题意:讲述了一种投小钱赢大钱的赌博方式,初始投入钱m,如果本局赢了,将钱连本带利投入下一局继续赌博。如果本局输了,之前得到的钱全部清零,如果打平,本局不赢钱。每局投入的钱数不能大于一百万,计算连本带利赢得的钱数,如果大于一百万则按赢了一百万。输入t组,然后是初始投入的钱m与赌博的局数n。在n局中,给出每局的Money Line,用于作为比率计算本局赢得的钱数。如果Money Line 大于0,则比率为Money Line/100,结果截取
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2830简单bfs 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int N=100005; 7 int head[N],vis[N]; 8 int cnt = 0; 9 struct Edge10 {11 int u,v;12 int next;13 } edge[4*N];14 struct node15 {16 i...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1293思路:设n = x1+x2+x3.....,要使f[x] = x1*x2*x3....最大,则x1=x2=x3.... 即f[x] = x^(n/x) , 两边同时取对数得:ln(f[x]) = (n/x)lnx, 令g(x) = ln(f[x]) =(n/x)lnx,对g(x)求导 得:g(x)' = n*(1-lnx),令 g(x)' = 0 得 x = e = 2.718..... 因为x为正整数,所以x=2或x=3
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2719 1 #include 2 #include 3 const int N=1010; 4 using namespace std; 5 int a[N],b[N],f[N]; 6 int main() 7 { 8 int n1,n2,m,o=0; 9 while(~scanf("%d %d %d",&n1,&n2,&m))10 {11 o++;12 int flag1 = 0,flag2...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2718题意:如果没有障碍就按原方向直走,否则就右转直走,若右边走不通就左转直走,若左边也走不通就后转直走,直到走出去。 1 #include 2 #include 3 const int N=50; 4 using namespace std; 5 int a[N][N]; 6 int main() 7 { 8 int n,m,k,x,y,p=0; 9 while(~scanf("%d %d %d",&n,&
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2493 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn=1010; 6 const int maxm=maxn*maxn; 7 const long long INF=1LLq;31 q.push(s);32 vis[s] = 1;33 dis[s] = 0;34 while(!q.empty())35 {36...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1269连着做了三个基本的dfs,终于弄懂了搜索和回溯的过程。此题要求输出所有路径,首先给每一个点编号0~n+m;则存储时只需存储编号,由编号得到坐标的方式: x = num/m, y = num%m; 由坐标得到编号的方式:num = x*m+y;注意:本题坐标从(1,1)开始,编号后的坐标从(0,0)开始。 1 #include 2 #include 3 const int Max = 20; 4 int map[Max][Max],vis[
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1590 1 #include 2 #include 3 int n,m,s_x,s_y,e_x,e_y; 4 char map[15][15]; 5 6 int Deal(char c) 7 { 8 if(c=='R'&&map[s_x][s_y+1]!='#') 9 {10 s_y++;11 if (s_x==e_x&&s_y==e_y)12 return 1;13 ...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2449 1 #include 2 #include 3 const int N=520; 4 int vis[N][N],map[N][N]; 5 int n,m,cnt; 6 void dfs(int x,int y) 7 { 8 if (x==n&&y==m) 9 {10 cnt++;11 return ;12 }13 if (x-1>=1&&map[x-1][y]==0&&!vis[.
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2566 1 #include 2 #include 3 char map[120][120]; 4 int v[120][120];//用来标记某点所能到达的所有路径 5 int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}}; 6 int n,m; 7 void dfs(int x,int y,int t) 8 { 9 v[x][y] = t;10 for (int i = 0; i = 0 &&
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1634将一个数表示成素数相乘的形式,其中素数从小到大排列。 1 #include 2 #include 3 #include 4 const int N=65536; 5 int a[N]; 6 void is_prime() 7 { 8 a[1] = 0,a[2] = 1; 9 for (int i = 3; i x)38 break;39 while(a[i])40 ...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1468简单的素数筛选会超时,因为是多组,所以先打表会更快,这样就不用每次都筛选了。 1 #include 2 #include 3 #include 4 const int N=1000002; 5 long long a[N]; 6 void printf_prime( ) 7 { 8 a[1] = 0; 9 a[2] = 1;10 for (int i = 3; i < N; i ++)11 {12 ...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2497题意:给定一些点和边的关系,判断S点是否在所构成无向图的所有环里。思路:用并查集将所有(除去S及与 S有关的点)有关系的点放在一个集合里,若此时图中还存在环,那么一定不包含S。 1 #include 2 #include 3 const int maxn = 10002; 4 5 int f[maxn],n; 6 int find(int x) 7 { 8 if (x!=f[x]) 9 f[x] = find(f[x...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1867 1 #include 2 #include 3 #include 4 const int maxn = 102; 5 const int INF=1 dis[i][k] + dis[k][j])//更新距离34 dis[i][j] = dis[i][k] + dis[k][j];35 }36 }37 }38 }39 int main()40 {41 ...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2138注意该图为有向图,1000个点应该最多有1000*999条边。在这跪了一下。。。 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 const int maxn=1000002; 8 int head[maxn],vis[maxn]; 9 int n,m,cnt;10 struct node11 {12 int u;13 int v;14 int...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2248题意:(1)求图中四连块(有公共边的方块)的个数; (2)求图中八连块(有公共顶点的方块)的个数。 1 #include 2 #include 3 const int N = 1010; 4 int vis1[N][N],map[N][N],vis[N][N]; 5 void dfs1(int x,int y)//搜索四个方向 6 { 7 if (!map[x][y]||vis1[x][y]) 8 return ; ...
阅读全文

浙公网安备 33010602011771号