这是第一题,像这种水题一定不要想复杂,思路不对立马换。
抓住串联和并联,可以用辗转相除法
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("!\n") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf("\n") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue int main() { long long a,b; while(sf("%I64d%I64d",&a,&b)==2) { long long cnt=0; while(a&&b) { if(a>b) { cnt+=a/b; a%=b; } else { cnt+=b/a; b%=a; } } pf("%I64d\n",cnt); } }
这题考看懂题意。。
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("!\n") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf("\n") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue int main() { int n,k; while(sf("%d%d",&n,&k)==2) { int sum =0; for(int i =0;i<n;i++) { int a,b; sf("%d%d",&a,&b); sum+=b-a+1; } pf("%d\n",(k-sum%k)%k); } }
这也是简单题,千万别先往复杂想。只要最后两个数字能被4整除,则这个数字就能被4整除,所以枚举最后两个数字就行
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("!\n") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf("\n") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue int main() { char a[1000000]; while(sf("%s",a)==1) { int len = strlen(a); LL cnt=0; for(int i = 0;i<len-1;i++) { int sum = (a[i]-‘0‘)*10+a[i+1]-‘0‘; if(sum%4==0) cnt+=i+1; } for(int i = 0;i<len;i++) { int sum = a[i]-‘0‘; if(sum%4==0) cnt++; } pf("%I64d\n",cnt); } }
其实可以化成长度为d的k进制的全排列
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("!\n") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf("\n") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue int num[1005],mp[1005][1005]; int n,k,d; int main() { while(sf("%d%d%d",&n,&k,&d)==3) { mem(num,0); mem(mp,0); if(n>pow((double)k,(double)d)) { pf("-1\n"); continue; } for(int i =0;i<n;i++) { int t = d-1; num[t]++; while(num[t]==k) { num[t]=0; num[t-1]++; t--; } memcpy(mp[i],num,sizeof(num)); } for(int i = 0;i<d;i++) { for(int j = 0;j<n;j++) pf("%d ",mp[j][i]+1); blank; } } }
时间: 2024-10-20 23:28:28