2 5 10 0
1 3 8鎬葷粨瑙勫緥錛?br>1錛?
1 1 2 3 3 3 0 0
1 8 14
In arithmetic we often use the scheme called 'round up by five' to round up a decimal fraction number into a decimal integer number whose fraction part equals to or is bigger than 0.5, otherwise, its fraction part is discarded.
In this problem, you are to implement a similar sheme called 'round up by six'.
The first line of the input is an integer N indicating the number of cases you are to process. Then from the second line there are N lines, each containing a number (may or may not be fractional).
For each number in the input, you are to print the round-up-by-six version of the number in a single line.
2 25.599 0.6
25 1
#include<iostream> #include<cmath> using namespace std; int main() {int n; cin>>n; while(n--) { double a; cin>>a; double b=floor(a); if(a-b>=0.6) cout<<b+1<<endl; else cout<<b<<endl; } return 0; }
int main()
{
//freopen("s.txt","r",stdin);
//freopen("key.txt","w",stdout);
cout<<kmp("fgfh","abcabfgfdhsfgfhdfdfhfcdab");//榪斿洖鐨勬槸鏁扮粍涓嬫爣錛屼粠0寮濮?
getchar();
//system("PAUSE");
return 0;
}
鏀硅繘鐨刱mp
----------------------浠ヤ笅鏄師kmp鐢熸垚next鍊肩殑綆楁硶---------------------
void createf(string pat)//find鏁扮粍
{
memset(f,0,sizeof(f));
int m=pat.size();
f[0]=-1;
for(int j=1;j<m;j++)
{
int i=f[j-1];
while(pat[j]!=pat[i+1]&&i>=0)//鍙p[j]涓巔[i+1]涓嶇瓑錛屽垯閫掓帹璁$畻i
i=f[i];
if(pat[j]==pat[i+1])
f[j]=i+1;
else
f[j]=-1;
}
}
/* 宸茬煡f[13]=6;acbacbcacbacb,姹俧[14]acbacbcacbacba鍒欏厛鍒ゆ柇pat[6+1]鏄惁絳変簬pat[14]錛屼笉絳?br> 鍐嶅垽鏂?i=f[6]acbacb=3;鍒ゆ柇pat[14]pat[3+1]鐩哥瓑錛屽垯i=3
鍙緱f[j]=3+1;
*/
-------------------浠ヤ笅榪樻槸鏈敼榪沰mp------------
void get_next(String T,int &next[])
{
i=1;j=0;next[1]=0;
while(i<=T.Length)
{
if(j==0 || T[i]==T[j]){++i;++j; next[i]=j;/**********(2)*/}
else j=next[j];
}
}
--------------------浠ヤ笅鏄敼榪涘瀷----------
涓婇潰鐨刦[j]鐩稿綋浜巒ext[]
int i,j,len,n;
len=strlen(s);
//KMP鏋勯?br> i=0,j=-1;
next[0]=-1;
while(i<len)
{
if(j==-1||s[i]==s[j])
{
i++,j++;
if(s[i]!=s[j])
next[i]=j;
else
next[i]=next[j];
// printf("next[%d]=%d\n",i,next[i]);
}
else j=next[j];
}
As you known,a positive integer can be written to a form of products of several positive integers(N = x1 * x2 * x3 *.....* xm (xi!=1 (1<=i<=m))).Now, given a positive integer, please tell me how many forms of products.
Input consists of several test cases.Given a positive integer N (2<=N<=200000) in every case.
For each case, you should output how many forms of the products.
12 100 5968
4 9 12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a[200001];
freopen("s.txt","r",stdin);
freopen("key.txt","w",stdout);
int i,j,n;
memset(a,0,sizeof(a));
a[1]=1;
for(i=1;i<=200000;i++)
for(j=1;i*j<=200000;j++)
a[i*j]+=a[j];
while(scanf("%d",&n)!=EOF)
printf("%d\n",a[n]/2);
//system("PAUSE");
return 0;
}