Topic One, jobdu1166: iterative seeking cube root
http://ac.jobdu.com/problem.php?pid=1166
-
Title Description:
-
The approximation iterative equation for cube root is y (n+1) = y (n) *2/3 + x/(3*y (n) *y (n)), where y0=x. The value of the given x after n iterations cube root.
-
Input:
-
Enter more than one set of data.
For each set of rows, enter x N.
-
Output:
-
Iterate n times after the cubic root, double the precision, preserving six digits after the decimal point.
-
Sample input:
-
3000000 28
-
Sample output:
-
144.224957
Topic Analysis:
Recursive or recursive, personal feeling recursion is very good, two variables loop forward can be.
AC Code:
<span style= "FONT-SIZE:18PX;" >/** * @xiaoran * recursive or recursive */ #include <iostream> #include <cstdio> #include <map># include<cstring> #include <string> #include <algorithm> #include <queue> #include <vector > #include <stack> #include <cstdlib> #include <cctype> #include <cmath> #define LL Long Longusing namespace Std;int Main () { double y,x,yy; int n; while (cin>>x>>n) { y=x; for (int i=1;i<=n;i++) { yy=y*2/3+x/(3*y*y); y=yy; } printf ("%.6lf\n", y); } return 0;} </span>
Topic Two, jobdu1167: array sorting
http://ac.jobdu.com/problem.php?pid=1167
-
Title Description:
-
Enter the value of an array to find the order in which each value is sorted from small to large.
-
Input:
-
Enter more than one set of data.
The first number of inputs per group is the length of an array of n (1<=n<=10000), followed by the number of values in the array, separated by a space.
-
Output:
-
The values of each input are arranged in order from small to large (there is no space behind the last digit).
-
Sample input:
-
4-3 75 12-3
-
Sample output:
-
1 3 2 1
- Topic Analysis:
- sort + Hash map, the STL map is very useful. Sort the subscript for each value of the record Oh.
AC Code:
<span style= "FONT-SIZE:18PX;" > #include <iostream> #include <algorithm> #include <map>using namespace Std;int a[10001],b[10001] , Cnt[10001];int Main () { int n; while (Cin>>n) {for (int i=0;i<n;i++) { cin>>a[i]; B[i]=a[i]; } Sort (a,a+n); Cnt[0]=1; map<int,int> num; Num[a[0]]=1; for (int i=1;i<n;i++) { if (a[i]==a[i-1]) num[a[i]]=num[a[i-1]]; else num[a[i]]=num[a[i-1]]+1; } for (int i=0;i<n-1;i++) { cout<<num[b[i]]<< ""; } cout<<num[b[n-1]]<<endl; } return 0;} </span>
Topic three, jobdu1168: Search and delete of string
http://ac.jobdu.com/problem.php?pid=1168
-
Title Description:
-
Given a short string (without spaces), and given a number of strings, delete the contained short string in these strings.
-
Input:
-
Enter only 1 sets of data.
Enter a short string (with no spaces), and then enter several strings until the end of the file.
-
Output:
-
Delete the input short string (case insensitive) and remove the whitespace, output.
-
Sample input:
-
in#include int main () {printf ("Hi");}
-
Sample output:
-
#cludetma () {prtf ("Hi");}
Topic Analysis:
Don't explain, look at the code. If you don't understand it, it is recommended to study library functions in C + +.
AC Code:
<span style= "FONT-SIZE:18PX;" >/** * @xiaoran * * #include <iostream> #include <cstdio> #include <map> #include <cstring># include<string> #include <algorithm> #include <queue> #include <vector> #include <stack> #include <cstdlib> #include <cctype> #include <cmath> #define LL long longusing namespace Std;int main () {string S1,s,s2;getline (Cin,s), for (int i=0;i<s.size (); i++) {if (Isalpha (S[i])) S[i]=tolower (S[i]);} int k=s.size (); while (Getline (CIN,S1)) {s2=s1; for (int i=0;i<s1.size (); i++) {if (Isalpha (S1[i])) S1[i]=tolower (S1[i]); } String::size_type pos=0; int ok=0; while ((Pos=s1.find (S,pos))!=string::npos) {//cout<<pos<<endl; S1.erase (POS,K); S2.erase (POS,K); ++pos; } for (int i=0;i<s2.size (); i++) {if (s2[i]!= ') cout<<s2[i]; } Cout<<endl;} return 0;} </span>
Nine degrees oj& Beihang University 2009 Machine Questions