cdoj 48 Cake 水题
Cake
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.uestc.edu.cn/#/problem/show/48
Description
ZC's birthday is comming, lxh gives a cake of n×m as present for his girlfriend.Now lxh wants to know how many second do you need to divide it to many 1×1 cakes? Every second you can choose a connected part of cake, and cut it into two along a straight line.
Input
In the first line, an integer T is given indects the number of test case.
For each case, you can get two interger n and m in the line. (n,m≤109)
Output
For each case, output the answer in a line.
Sample Input
2
1 1
2 2
Sample Output
0
3
HINT
题意
题解:
答案是a*b-1,会爆int
代码:
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 200000 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** int main() { int t=read(); while(t--) { ll a=read(),b=read(); cout<<a*b-1<<endl; } }