codeforces 724
题目链接:
http://codeforces.com/contest/724
1 second
256 megabytes
standard input
standard output
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes).
monday
tuesday
NO
sunday
sunday
YES
saturday
tuesday
YES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=5e5+10;
string str1,str2;
int check(string s)
{
if(s=="monday")return 0;
else if(s=="tuesday")return 1;
else if(s=="wednesday")return 2;
else if(s=="thursday")return 3;
else if(s=="friday")return 4;
else if(s=="saturday")return 5;
else return 6;
}
int main()
{
cin>>str1>>str2;
int a=check(str1),b=check(str2);
int t=(b-a+7)%7;
if(28%7==t||30%7==t||31%7==t)printf("YES\n");
else printf("NO\n");
return 0;
}
/* 题意: 水; 思路:
水;
*/
2 seconds
256 megabytes
standard input
standard output
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order.
You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table.
Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m.
If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
2 4
1 3 2 4
1 3 4 2
YES
4 4
1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3
NO
3 6
2 1 3 4 5 6
1 2 4 3 5 6
1 2 3 4 6 5
YES
#include <bits/stdc++.h>
using namespace std;
int n,m,a[23][23],num[23],flag=1;
int check(int x,int y)
{
for(int i=1;i<=n;i++)
{
int cnt=0;
for(int j=1;j<=m;j++)
{
if(j==x)
{
if(a[i][j]!=y)cnt++;
}
else if(j==y)
{
if(a[i][j]!=x)cnt++;
}
else
{
if(a[i][j]!=j)cnt++;
}
}
if(cnt>2)return 0;
}
return 1;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&a[i][j]);
for(int i=1;i<=n;i++)
{
num[i]=0;
for(int j=1;j<=m;j++)
{
if(a[i][j]!=j)num[i]++;
}
if(num[i]>4)
{
cout<<"NO";
return 0;
}
if(num[i]>2)flag=0;
}
if(flag)
{
cout<<"YES";
return 0;
}
flag=0;
for(int i=1;i<=m;i++)
{
for(int j=i+1;j<=m;j++)
{
if(check(i,j))flag=1;
}
}
if(flag)cout<<"YES";
else cout<<"NO";
return 0;
}
/* 题意: 每行交换最多一次,最后还可以交换两列,问最后每行是否都能变成1,2,...m的排列; 思路: 枚举最后要交换哪两列,然后判断每行是否能在一次变换中变成列交换之前的状态,还有判断不进行列交换的时候;
*/
2 seconds
256 megabytes
standard input
standard output
There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (xi, yi). All sensors are located at distinct points strictly inside the rectangle.
Opposite corners of the room are located at points (0, 0) and (n, m). Walls of the room are parallel to coordinate axes.
At the moment 0, from the point (0, 0) the laser ray is released in the direction of point (1, 1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1, 1) in exactly one second after the start.
When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.
For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print - 1 for such sensors.
The first line of the input contains three integers n, m and k (2 ≤ n, m ≤ 100 000, 1 ≤ k ≤ 100 000) — lengths of the room's walls and the number of sensors.
Each of the following k lines contains two integers xi and yi (1 ≤ xi ≤ n - 1, 1 ≤ yi ≤ m - 1) — coordinates of the sensors. It's guaranteed that no two sensors are located at the same point.
Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or - 1 if this will never happen.
3 3 4
1 1
1 2
2 1
2 2
1
-1
-1
2
3 4 6
1 1
2 1
1 2
2 2
1 3
2 3
1
-1
-1
2
5
-1
7 4 5
1 3
2 2
5 1
5 3
4 3
13
2
9
5
-1
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL inf=1e18;
const int maxn=1e5+5;
int k,fx[maxn],fy[maxn];
LL dir[4][2]={-1,1,-1,-1,1,1,1,-1};
LL tx[4],ty[4],n,m;
LL gcd(LL a,LL b,LL &x,LL &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
LL ans=gcd(b,a%b,x,y);
LL temp=x;
x=y;
y=temp-a/b*y;
return ans;
}
LL GCD(LL a,LL b)
{
if(!b)return a;
return GCD(b,a%b);
}
LL solve(LL fn,LL fm)
{
LL b=fm-fn;
LL x,y,d;
d=gcd(n,-m,x,y);
if(b%d!=0)return -1;
if(b%m==0)return fn;
LL lcm=abs(n*m/d);
x=x*(b/d);
LL ans=((x*n+fn)%lcm+lcm)%lcm;
if(ans==0)ans=lcm;
return ans;
}
int main()
{
scanf("%I64d%I64d%d",&n,&m,&k);
for(int i=1;i<=k;i++)scanf("%d%d",&fx[i],&fy[i]);
LL hi=n/GCD(n,m)*m;
n*=2;m*=2;
for(int i=1;i<=k;i++)
{
LL ans=inf;
for(int j=0;j<4;j++)
{
LL temp=solve(fx[i]*dir[j][0],fy[i]*dir[j][1]);
if(temp>0&&temp<=hi)ans=min(ans,temp);
}
if(ans==inf)printf("-1\n");
else printf("%I64d\n",ans);
}
return 0;
}
/*
题意:
给出一束光从(0,0)出发,一直到角落才会停,问光到达给出的这些点的最短时间是多少; 思路: 可以发现这些点在平面上镜面对称后得到的点是(2*k*n+-x,2*t*m+-y);然后坐标相等,就是解同余方程了;
范围在(0,lcm(n,m))才是正确的;
*/
2 seconds
256 megabytes
standard input
standard output
You are given a string s, consisting of lowercase English letters, and the integer m.
One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.
Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order.
Formally, we choose a subsequence of indices 1 ≤ i1 < i2 < ... < it ≤ |s|. The selected sequence must meet the following condition: for every j such that 1 ≤ j ≤ |s| - m + 1, there must be at least one selected index that belongs to the segment [j, j + m - 1], i.e. there should exist a k from 1 to t, such that j ≤ ik ≤ j + m - 1.
Then we take any permutation p of the selected indices and form a new string sip1sip2... sipt.
Find the lexicographically smallest string, that can be obtained using this procedure.
The first line of the input contains a single integer m (1 ≤ m ≤ 100 000).
The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string s.
Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.
3
cbabc
a
2
abcab
aab
3
bcabcbaccba
aaabb
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int m;
char s[maxn],ans[maxn],tep[maxn];
int main()
{
scanf("%d",&m);
scanf("%s",s);
int len=strlen(s),cnt,num;
for(int i=len-1;i>=0;i--)s[i+1]=s[i];
for(char temp='a';temp<='z';temp++)
{
int p=0,flag=1,fp=0;num=0;
for(int i=1;i<=len;i++)
{
if(i<=p+m)
{
if(s[i]<temp)tep[num++]=s[i],p=i;
else if(s[i]==temp)fp=i;
}
else
{
if(fp>p)
{
tep[num++]=s[fp],p=fp;i--;
}
else {flag=0;break;}
}
}
if(flag)
{
for(int i=0;i<num;i++)ans[i]=tep[i];
cnt=num;
break;
}
}
if(cnt==0)
{
char d='z';
for(int i=1;i<=len;i++)d=min(d,s[i]);
cnt=1;
ans[0]=d;
}
sort(ans,ans+cnt);
for(int i=0;i<cnt;i++)printf("%c",ans[i]);
return 0;
}
/*
题意:
每隔m个字符选一个,使得选中的这些字符排序后字典序最小; 思路: 枚举最大的那个字符,遍历一遍,比其小的全要,相等的要当前范围最后一个;
*/
codeforces 724的更多相关文章
- Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS
G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组 ...
- Codeforces 724 E Goods transportation
Description 有 \(n\) 个点,每个点有一个入流和出流,每个点与编号比它大的点连边,容量为 \(c\) ,求最大流. Sol DP. 这种特殊的图可以DP,把最大流转化成最小割. 最小割 ...
- 刷题记录:Codeforces Round #724 (Div. 2)
Codeforces Round #724 (Div. 2) 20210713.网址:https://codeforces.com/contest/1536. div2明显比div3难多了啊-只做了前 ...
- codeforces 724D(贪心)
题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...
- codeforces 724B Batch Sort(暴力-列交换一次每行交换一次)
题目链接:http://codeforces.com/problemset/problem/724/B 题目大意: 给出N*M矩阵,对于该矩阵有两种操作: (保证,每行输入的数是 1-m 之间的数且不 ...
- Codeforces 724E Goods transportation(最小割转DP)
[题目链接] http://codeforces.com/problemset/problem/724/E [题目大意] 每个城市有pi的物品可以运出去卖,si个物品可以买, 编号小的城市可以往编号大 ...
- 【codeforces 724E】Goods transportation
[题目链接]:http://codeforces.com/problemset/problem/724/E [题意] 有n个城市; 这个些城市每个城市有pi单位的物品; 然后已知每个城市能卖掉si单位 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- Python可变参数
#!/usr/bin/env python # -*- coding: utf-8 -*- import math def calc(*numbers): sum=0 for n in numbers ...
- CSS之绝对定位那些事
1.垂直居中 有时我们会使用margin: 0 auto;作居中使用.但有的时候我们需要垂直居中,例如在div里面垂直居中显示一张加载中的gif图. 下面这种写法就可以完美实现: 垂直居中的子容器 { ...
- jQuery UI resizble、draggable的div包含iframe导致缩放和拖拽的不平滑解决方法
前言 不仅仅是jQuery UI resizble的div包含iframe会导致缩放的不平滑,draggable也会出现包含iframe会导致拖放的不平滑,但是因为jQuery UI有为draggab ...
- ASP.NET MVC:窗体身份验证及角色权限管理示例
ASP.NET MVC 建立 ASP.NET 基础之上,很多 ASP.NET 的特性(如窗体身份验证.成员资格)在 MVC 中可以直接使用.本文旨在提供可参考的代码,不会涉及这方面太多理论的知识. 本 ...
- Vue基础理论
一 vue的定位 (1)Vue.js是一个构建数据驱动的 web 界面的库. (2)Vue.js 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件. (3)Vue.js 自身不是一 ...
- CSS选择器特殊性与重要性
特殊性 在编写CSS代码的时候,我们会出现多个样式规则作用于同一个元素的情况,例如 <!-- HTML --> <header> <nav class="nav ...
- java调用html模板发送html内容的邮件
在项目需要发送邮件,普通内容的邮件觉得太单调.太丑,没逼格,所以说直接把用到的邮件内容做成一个html模板,发送之前将对应参数替换掉,发送html内容的高逼格邮件. 首先需要引用jar包,这就不多说了 ...
- owl-carousel轮播插件的使用
插件github地址:https://github.com/OwlFonk/OwlCarousel: 插件官网演示地址:http://owlgraphic.com/owlcarousel/: 1.选择 ...
- 正确匹配URL的正则表达式
网上流传着多种匹配URL的正则表达式版本,但我经过试验,最好用的还是从stackoverflow上查到的: (https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_| ...
- 详解Paint的各种set方法
一.前言 我们用set方法来设置画笔的样式,类似于我们挑选画笔画画的过程.由于上面有些方法不支持硬件加速,所以在高版本系统中可能会没有效果.因此,我们首先来看看官方废弃的方法. 下图来自:https: ...