赞
踩
- #include <bits/stdc++.h>
- #define endl '\n'
- #define int long long
- #define INF 0x3f3f3f3f3f
- const int N = 1000010;
- using namespace std;
- int arr[N];
- signed main()
- {
- int N;
- cin>>N;
- int idx;
- while(cin>>arr[++idx]){}
- //排序
- sort(arr+1,arr+idx+1);
- int ans1,ans2;
- for(int i = 1; i <= idx; i++){
- if(arr[i+1] - arr[i] == 2)
- ans1 = arr[i]+1;
- if(arr[i+1] == arr[i])
- ans2 = arr[i];
-
- }
- cout<<ans1<<' '<<ans2;
- return 0;
- }
- #include<bits/stdc++.h>
- #define ll longlong
-
- using namespace std;
-
-
-
- int a[100010];
- int main(){
-
- int n = 5;
- string s;
- int ans = 0;
- for(int i = 0; i < n;i++ ){
- cin>>s;
- if(s[0] == s[2]&& s[3] - s[1] == 1)
- ans++;
- }
- cout<<ans;
-
- return 0;
- }
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
-
- const int N = 100010;
- signed main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
-
- int n;
- cin>>n;
- int cnt= 0 ;
- for(int i = 1; i<= n-1; i++){
- int x = i*i;
- if((x % n) < n/2.0){
- cnt++;
- }
- }
- cout<<cnt;
- return 0;
- }
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
-
- const int N = 100010;
- signed main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
-
- int a,b,n;
- cin>>a>>b>>n;
- int sum = 0;
- int cnt = 1;
- while(sum<n){
- if(cnt % 7>=1&& cnt%7<=5)
- sum+=a;
- else
- sum+=b;
- cnt++;
-
- }
-
- cout<<cnt-1;
- return 0;
- }
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
-
- const int N = 100010;
- signed main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
-
- string s;
- cin>>s;
- for(int i = 0;i < s.size();i++){
- if(s[i]>='1'&& s[i]<='9')
- for(int j = 0 ; j < s[i]-'1';j++)
- cout<<s[i-1];
- else
- cout<<s[i];
- }
- return 0;
- }
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
-
- const int N = 100010;
- signed main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
-
- int n;
- int a[N];
- cin>>n;
- for(int i = 0 ;i < n;i++){
- cin>>a[i];
- }
-
- sort(a,a+n);
- double sum = 0;
- for(int i = 0 ; i < n;i++)
- sum+= a[i];
- double ans = sum/n*1.0;
- cout<<a[n-1]<<endl<<a[0]<<endl;
- printf("%.2lf",ans);
- return 0;
- }
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
-
- const int N = 100010;
- signed main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n ;
- cin>>n;
- while(n>0){
- cout<<n<<" ";
- n = n>>1;
- }
- return 0;
- }
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
- unordered_map<string,int> mp{//创立哈希表,建立字符到整形的映射
- {"Jan",1},
- {"Feb",2},
- {"Mar",3},
- {"Apr",4},
- {"May",5},
- {"Jun",6},
- {"Jul",7},
- {"Aug",8},
- {"Sep",9},
- {"Oct",10},
- {"Nov",11},
- {"Dec",12}
- };
- const int N = 100010;
- signed main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
-
- string s;
- cin>>s;
- string s1 = s.substr(0,3);
- string s2 = s.substr(3);
-
- cout<<mp[s1]<<" ";
- if(s2[0] != '0')
- cout<<s2[0];
-
- cout<<s2[1];
- return 0;
- }
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
-
-
- const int N = 100010;
- signed main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
-
- int n;
- int ans = 0;
- cin>>n;
- for(int i = 1;i<=n;i++){
- string s = to_string(i);
- for(int j =0; j <s.size();j++){
- if(s[j] == '0' || s[j] =='1'||s[j] =='2'||s[j] == '9')
- { ans+=i;
- break;
- }
- }
- }
- cout<<ans;
- return 0;
- }
- #include<bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
-
-
- const int N = 100010;
- signed main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
-
- int n;
- cin>>n;
- int a,b;
- int ans_min = 0,ans_max = 1e9;
- for(int i= 0; i< n;i++){
- cin>>a>>b;
- ans_min = max(ans_min,a/(b+1)+1);
- ans_max = min(ans_max,a/b);
- }
- cout<<ans_min<<" "<<ans_max;
- return 0;
- }
- #include <bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f3f
- using namespace std;
- const int N = 100010;
- int arr[N];
-
- signed main(){
-
- string a,b;
- cin>>a>>b;
- int cnt = 0;
- for(int i = 0 ; i < a.size();i++){
- if(a[i]!=b[i]){
- a[i] = a[i] == 'o'?'*':'o';
- a[i+1] = a[i+1] =='o'?'*':'o';
- cnt++;
- }
-
- }
- cout<<cnt;
-
- return 0;
- }
- #include <bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f3f
- using namespace std;
- const int N = 100010;
- int a[N],b[N];//长宽
- int n,k;
-
- bool check(int mid){
- int cnt =0 ;
- for(int i = 1 ; i <= n ;i++){
- cnt+=(a[i]/mid)*(b[i]/mid);
- }
- if(cnt>=k)return true;
- else return false;
- }
-
- signed main(){
-
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin>>n>>k;
- for(int i = 1; i <= n;i++){
- cin>>a[i]>>b[i];
- }
- int l = 0;
- int r = 10010;
- while(l+1<r){
- int mid = (l+r)>>1;
- if(check(mid))
- l = mid;
- else
- r = mid;
- }
- if(check(r)) cout<<r;
- else cout<<l;
- return 0;
- }
=(a2+a3+⋯+an)⋅a1+(a3+a4+⋯+an)⋅a2+⋯+an⋅an−1
- #include <bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f3f
- using namespace std;
- const int N = 200010;
- int arr[N],sum[N];
- int n;
- int ans;
- signed main(){
-
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin>>n;
- for(int i = 1 ; i<=n;i++){
- cin>>arr[i];
- sum[i] = sum[i-1] + arr[i];
- }
- for(int i =1 ;i <=n-1 ;i++){
- ans += arr[i]*(sum[n]-sum[i]);
- }
- cout<<ans;
- return 0;
- }
scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&s1,&h2,&m2,&s2);
- #include <bits/stdc++.h>
- #define endl '\n'
- #define INF 0x3f3f3f3f3f
- const int N = 1000010;
- using namespace std;
-
- int get()
- {
- int h1,m1,s1,h2,m2,s2,day=0;
- scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&s1,&h2,&m2,&s2);
- if(getchar()==' ')scanf("(+%d)",&day);
- return (day*86400+h2*3600+m2*60+s2)-(h1*3600+m1*60+s1);
- }
- signed main()
- {
- int T;
- scanf("%d",&T);
- while(T--)
- {
- int ans=(get()+get())/2;
- printf("%02d:%02d:%02d\n",ans/3600,ans%3600/60,ans%60);
- }
- return 0;
- }
设深度为 dep,根节点的深度为 1。则有第 dep 层的节点为 2dep,每层开头的节点编号为 2dep−1,末尾的节点编号为 2dep−1(以上结论叶子节点除外)。
- #include <bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
- const int N = 100010;
- int arr[N];
- int n;
- int dep = 1,sum = 0,Max = -1,a,ans;
- signed main(){
-
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin>>n;
- for(int i = 1; i <= n; i++){
- cin>>a;
- sum+=a;
- if(i == (1<<dep)-1){//判断当前位置是否是该dep的最后一个节点?结算:go on
- if(sum>Max){
- Max = sum;
- ans = dep;
- }
- dep++;
- sum = 0;
- }
- }
- if(sum>Max){//叶子节点特判
- Max = sum;
- ans = dep;
- }
-
- cout<<ans;
- return 0;
- }
- #include <bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
- const int N = 100010;
- int arr[N];
- int n;
- int f(int x) {//小于等于x的奇数个数
- if (!x) return 0;
- return (x + 1) / 2;
- }
- int g(int x) {//小于等于x的4的倍数个数
- return x / 4;
- }
- signed main(){
-
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int l, r; cin >> l >> r;
- cout << f(r) - f(l - 1) + g(r) - g(l - 1);
- return 0;
- }
- #include <bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
- const int N = 1e8;
- bool check(string s){
- int ans1 = 0 ,ans2 = 0;
- for(int i = 0; i < s.size();i++){
- if(i<s.size()/2)
- ans1 += s[i]-'0';
- else
- ans2 += s[i]-'0';
- }
- return ans1 == ans2;
- }
- signed main(){
-
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- string s;
- int ans = 0;
- for(int i = 1 ; i<= N;i++){
- s= to_string(i);
- if(s.size()%2 == 1)continue;//奇数
- if(check(s)) {
- ans++;
- }
-
- }
- cout<<ans;
- return 0;
- }
- #include <bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
- const int N = 1e8;
- int arr[N];
- int ans;
- void dfs(int score,int cnt){
- if(cnt>30||score == 100)
- return;
- if(cnt == 30 && score == 70)
- ans++;
- dfs(score+10,cnt+1);
- dfs(0,cnt+1);
- }
-
-
- signed main(){
-
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- //表示0分 0题
- dfs(0,0);
- cout<<ans;
- return 0;
- }
- #include <bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
- const int N = 100010;
- int arr[N],sum[N];
- int n,k;
- map<int,int> mp;
-
- signed main(){
-
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin>>n>>k;
- int ans = 0;
- mp[0] = 1;
- for(int i = 1; i<=n;i++){
- cin>>arr[i];
- sum[i] = (sum[i-1]+ arr[i])%k;//记录前缀和模k的值
- mp[sum[i]]++;
- }
- for(int i = 0; i< n;i++){
- ans+=(mp[i]*(mp[i]-1))/2;
- }
- cout<<ans;
- return 0;
- }
0可以单独算也可以组在一起 满足
- #include <bits/stdc++.h>
- #define int long long
- #define endl '\n'
- #define INF 0x3f3f3f3f
- using namespace std;
- const int N = 100010;
- int arr[N],sum[N];
- int n,k;
- map<int,int> mp;
-
- signed main(){
-
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin>>n>>k;
- int ans = 0;
- for(int i = 1; i<=n;i++){
- cin>>arr[i];
- sum[i] = (sum[i-1]+ arr[i])%k;//记录前缀和模k的值
- mp[sum[i]]++;
- }
- for(auto i :mp){
- if(i.first == 0)
- ans+=i.second*(i.second+1)/2;
- else
- ans+=i.second*(i.second-1)/2;
- }
- cout<<ans;
- return 0;
- }
而偶数行为(把奇数行的横坐标倒换):
- #include<bits/stdc++.h>
- #define int long long
- #define INF 0x3f3f3f3f
- #define end '\n'
- const int N = 10010;
- using namespace std;
-
- signed main(){
-
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int w,m,n;
- cin>>w>>m>>n;
- m--;//预处理
- n--;
- int x1 = m%w, y1 = m/w,x2 = n%w,y2 = n/w;
- if(y1%2 == 1){//判断奇偶层数
- x1 = w-1-x1;
- }
- if(y2%2 == 1){
- x2 = w-1-x2;
- }
- cout<<abs(x2-x1) + abs(y2-y1)<<endl;//绝对值防止n比m大
-
-
- return 0;
- }
- #include<bits/stdc++.h>
- #define int long long
- #define INF 0x3f3f3f3f
- #define end '\n'
- const int N = 100010;
- using namespace std;
- int arr[N];
-
- int gcd(int x,int y){
- if(y == 0)
- return x;
- return gcd(y, x % y);
- }
-
- signed main(){
-
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin>>n;
- for(int i = 1; i <= n ;i++){
- cin>>arr[i];
- }
- sort(arr+1,arr+n+1);//排序
- if(arr[1]==arr[n]){//加特判 d为0
- cout<<n;
- return 0;
- }
- int d = arr[2]-arr[1];
- for(int i = 2 ; i <= n;i++){
- d = gcd(d,arr[i]-arr[i-1]);
- }
- cout<<(arr[n]-arr[1])/d+1<<endl;//求项数
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。