锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 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. int main() 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. int main()Input
杈撳叆鐨勬瘡涓琛屾湁鍗曠嫭鐨勪竴涓糿銆俷=0鏍囧織杈撳叆緇撴潫
Output
瀵逛簬杈撳叆鐨勬瘡涓琛岋紝浣跨敤鍗曠嫭涓琛岃緭鍑哄搴旂粨鏋溿?
Sample Input
2
5
10
0
Sample Output
1
3
8
鎬葷粨瑙勫緥錛?br>1錛?
2錛?
3錛?
4錛?
5錛?
6錛?
7錛?
8錛?
9錛?
10錛?
11錛?
12錛?0
16錛?5
32錛?1
64錛?3
浣犱細鍙戠幇2^n鐨勯兘鏄?^n-1
鍏朵粬13=8+4+1=(8-1)+(4-1)+(1-1),鏈夊灝戜釜2^n,鍒欏噺澶氬皯嬈?銆?br>鐩存帴鏍規(guī)嵁浣嶈繍綆楀嵆鍙眰
]]>
For Example, when N = 2 and M = 3, there are 6 squares size of 1 * 1 and 2 squares size of 2 * 2 in the chessboard, so the answer is 8.
Input
There are several lines in the input, each line consist of two positive integers N and M (1 <= N <= 100, 1 <= M <= 100) except the last line which N = 0 and M = 0 implying the end of the input and you should not process it.
Output
Please output the number of the squares for each chessboard in a single line.
Sample Input
1 1
2 3
3 3
0 0
Sample Output
1
8
14
鍚彂錛氫漢鏄庝箞綆楃殑錛屽氨璁╃▼搴忔庝箞綆楋紝涓姝ヤ竴姝ユ帹銆?br>#include<iostream>
using namespace std;
int main()
{
int n,m;
long sum=0;
int i;
while(cin>>n>>m,n)
{
if(n==m)
{
sum=n*(n+1)*(2*n+1)/6;
cout<<sum<<endl;
}
else
{
for(i=0;i<n&&i<m;i++)
sum+=(n-i)*(m-i);
cout<<sum<<endl;
}
sum=0;
}
return 0;
}
]]>Input
Output
Sample Input
2
25.599
0.6
Sample Output
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;
}
]]>
涓嬮潰鐨勪及璁℃垜閮界湅涓嶆噦
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
int f[100];
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;
*/
int kmp(string pat,string str)//姹俻at鍦╯tr涓殑絎竴涓尮閰嶇殑璧風偣
{
int p=0,s=0;
createf(pat);
int m=pat.size();
int n=str.size();
while(p<m&&s<n)
{
if(pat[p]==str[s])
{
p++;s++;
}
else
{
if(p==0)s++;
else
p=f[p-1]+1;//s鏃犻渶鍙樺寲,涓句緥錛宎bababababba
/* |
s鎸囧悜a
ababb
// |
// p鎸囧悜b,s鍜宲澶遍厤
abababababba
// |
s s涓嶅彉
鐢變簬ab=ab錛屾棦f[p-1]=2 ababb
// p=f[p-1]+1=3 |
// p 鍥炲埌f[p-1]+1鐨勪綅緗?
鐩哥瓑錛屽垯s鍜宲閮藉姞1.
//
*/
}
}
if(p<m)
return -1;
return s-m;
}
{
//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];
}
]]>Input
Output
Sample Input
12
100
5968
Sample Output
4
9
12
#include<iostream>
#include<cstdlib>
using namespace std;
{
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;
}
鍙戠幇閫掓帹瑙勫緥瑕佷粠鐗圭偣鍜屽嚭鍙戯紝涔樻硶鑷劧鏄箻娉曘?
]]>